コード例 #1
0
    public async Task Part1_CreateSchema()
    {
        // 1. Create builder
        var builder = new SchemaBuilder();

        // 2. Create Query type from SDL by defining a type with 
        // name Query. This is by convention.
        builder.Add(@"
                type Query {
                    name: String
                }
                ");

        // 3. Build schema
        var schema = await builder.Build(new SchemaBuildOptions());

        // Assert that created schema matches the inputs
        // note: By convention the name on the Query root type is Query
        Assert.Equal("Query", schema.Query.Name);

        // Schema has methods for querying the fields of the type.
        // In this case assertion is done to check that "name" field exists
        // for Query type. Fields are key value pairs where key is the name
        // of the field and value is the actual field.
        Assert.Single(
            schema.GetFields(schema.Query.Name),
            fieldDef => fieldDef.Key == "name");
    }
コード例 #2
0
    public static async Task <ISchema> Create()
    {
        var typeDefs = @"
type Review @key(fields: ""id"") {
    id: ID!
    body: String
    author: User @provides(fields: ""username"")
    product: Product
}

type User @key(fields: ""id"") @extends {
    id: ID! @external
    username: String @external
    reviews: [Review]
}

type Product @key(fields: ""upc"") @extends {
    upc: String! @external
    reviews: [Review]
}

type Query {
}
";

        var builder = new SchemaBuilder();

        builder.Add(typeDefs);

        var resolvers = new ResolversMap
        {
コード例 #3
0
    public static SchemaBuilder Create()
    {
        var builder = new SchemaBuilder();

        builder.Add(GetTypeSystem());

        return(builder);
    }
コード例 #4
0
    public static SchemaBuilder AddIntrospectedSchema(this SchemaBuilder builder, __Schema schema)
    {
        foreach (var schemaType in schema.Types)
        {
            builder.Add(schemaType);
        }

        return(builder);
    }
コード例 #5
0
    public ExecutionPathFacts()
    {
        // schema
        var builder = new SchemaBuilder();

        builder.Add((TypeSystemDocument) @"
type Node {
    child: Node
    path: [String]
    value: String
    children: [Node]
}

type Query {
    root: Node
}

type Mutation {
    root: Node
}

");

        var resolvers = new ResolversMap
        {
            {
                "Query", new FieldResolversMap
                {
                    { "root", context => new ValueTask <IResolverResult>(Resolve.As(new { })) }
                }
            },
            {
                "Mutation", new FieldResolversMap
                {
                    { "root", context => new ValueTask <IResolverResult>(Resolve.As(new { })) }
                }
            },
            {
                "Node", new FieldResolversMap
                {
                    { "child", context => new ValueTask <IResolverResult>(Resolve.As(new { })) },
                    {
                        "children", context => new ValueTask <IResolverResult>(Resolve.As(new[]
                        {
                            new { id = 0 },
                            new { id = 1 }
                        }))
                    },
                    { "value", context => new ValueTask <IResolverResult>(Resolve.As("value")) },
                    { "path", context => new ValueTask <IResolverResult>(Resolve.As(context.Path.Segments)) }
                }
            }
        };

        _schema = builder.Build(resolvers).Result;
    }
コード例 #6
0
    public IntrospectSchemaFacts()
    {
        var builder = new SchemaBuilder();

        builder.Add(@"

""""""Description""""""
interface Interface 
{
    int: Int    
}

""""""Description""""""
type Object implements Interface
{
    int: Int
    """"""Description""""""
    nonNullInt(arg1: Float = 1): Int!
}

type Object2 
{
    int: [Int]
}

""""""Description""""""
union Union = Object | Object2

""""""Description""""""
enum Enum {
    """"""Description""""""
    VALUE1
    
    """"""Description""""""
    VALUE2 @deprecated(reason: ""reason"")
}

""""""Description""""""
input InputObject 
{
    """"""Description""""""
    field1: Boolean = true
}

type Query {
    object: Object
    union: Union
    enum: Enum
    listOfObjects: [Object2]
    nonNullObject: Object1!

    """"""Description""""""
    inputObjectArg(arg1: InputObject): Boolean!
}

type Mutation {}
type Subscription {}
");


        _introspectionSchema = builder.Build(new SchemaBuildOptions()
        {
            IncludeIntrospection = true // note: on by default
        }).Result;
    }