Creating a schema
Schema defines the structure against which your queries are executed.
See also
Schema creation includes following steps:
- Create instance of
SchemaBuilder
- Create query root type
- Build schema
[Fact]
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");
}