public void Select_Schema_Enum_Types() { var expression = new IntrospectionQuery() .Schema .Select(x => new SchemaModel { Types = x.Types.Select(t => new TypeModel { Fields = t.Fields(true).Select((Field f) => new FieldModel { Name = f.Name, }).ToList(), EnumValues = t.EnumValues(true).Select((EnumValue e) => new EnumValueModel { Name = e.Name, }).ToList(), }).ToList() }); var expectedQuery = @"query { __schema { types { fields(includeDeprecated: true) { name } enumValues(includeDeprecated: true) { name } } } }"; var query = expression.Compile(); Assert.Equal(expectedQuery, query.ToString(), ignoreLineEndingDifferences: true); }
public void Select_Schema_QueryType_Kind() { var expected = "query{__schema{queryType{kind}}}"; var expression = new IntrospectionQuery() .Schema.QueryType .Select(x => x.Kind); var query = expression.Compile(); Assert.Equal(expected, query.ToString(0)); }
public void Select_Schema_QueryType_Kind() { var expected = "{__schema{queryType{kind}}}"; var expression = new IntrospectionQuery() .Schema.QueryType .Select(x => x.Kind); var query = new QueryBuilder().Build(expression); var result = new QuerySerializer().Serialize(query.OperationDefinition); Assert.Equal(expected, result); }
private async Task <IntrospectionQueryData> GetSchemaAsync(ISchema schema) { var options = new ExecutionOptions { Schema = schema, Query = IntrospectionQuery.GetQuery() }; var result = await _documentExecuter.ExecuteAsync(options); using var stream = new MemoryStream(); await _documentWriter.WriteAsync(stream, result); stream.Position = 0; var response = await IntrospectionQuery.DeserializeAsync(stream); return(response?.Data); }
public void Select_Schema_Enum_Types() { var expression = new IntrospectionQuery() .Schema .Select(x => new SchemaModel { Types = x.Types.Select(t => new TypeModel { Fields = t.Fields(true).Select((Field f) => new FieldModel { Name = f.Name, }).ToList(), EnumValues = t.EnumValues(true).Select((EnumValue e) => new EnumValueModel { Name = e.Name, }).ToList(), }).ToList() }); var expectedQuery = @"{ __schema { types { fields(includeDeprecated: true) { name } enumValues(includeDeprecated: true) { name } } } }"; var query = new QueryBuilder().Build(expression); var queryResult = new QuerySerializer(2).Serialize(query.OperationDefinition); Assert.Equal(expectedQuery, queryResult); }
public void Select_Schema_Types() { var expectedQuery = @"query { __schema { types { kind name description fields(includeDeprecated: true) { name description type { name } } } } }"; var data = @"{ ""data"": { ""__schema"": { ""types"": [ { ""kind"": ""SCALAR"", ""name"": ""Scalar"", ""description"": ""A scalar value."", ""fields"": null }, { ""kind"": ""INPUT_OBJECT"", ""name"": ""InputObject"", ""description"": ""An input object."", ""fields"": null }, ] } } }"; var expression = new IntrospectionQuery() .Schema .Select(x => new SchemaModel { Types = x.Types.Select(t => new TypeModel { Kind = t.Kind, Name = t.Name, Description = t.Description, Fields = t.Fields(true).Select(f => new FieldModel { Name = f.Name, Description = f.Description, Type = f.Type.Name, }).ToList() }).ToList() }); var query = (SimpleQuery <SchemaModel>)expression.Compile(); Assert.Equal(expectedQuery, query.ToString(), ignoreLineEndingDifferences: true); var responseResult = new ResponseDeserializer().Deserialize(query, data); var type = responseResult.Types[0]; Assert.Equal(TypeKind.Scalar, type.Kind); Assert.Equal("Scalar", type.Name); Assert.Equal("A scalar value.", type.Description); type = responseResult.Types[1]; Assert.Equal(TypeKind.InputObject, type.Kind); Assert.Equal("InputObject", type.Name); Assert.Equal("An input object.", type.Description); }
public static async Task<SchemaModel> ReadSchema(IConnection connection) { var query = new IntrospectionQuery() .Schema .Select(x => new SchemaModel { QueryType = x.QueryType.Name, MutationType = x.MutationType.Name, Types = x.Types.Select(t => new TypeModel { Kind = t.Kind, Name = t.Name, Description = t.Description, Fields = t.Fields(true).Select((Field f) => new FieldModel { Name = f.Name, Description = f.Description, Type = f.Type.Select((SchemaType t1) => new TypeModel { Kind = t1.Kind, Name = t1.Name, OfType = t1.OfType.Select((SchemaType t2) => new TypeModel { Kind = t2.Kind, Name = t2.Name, OfType = t2.OfType.Select((SchemaType t3) => new TypeModel { Kind = t3.Kind, Name = t3.Name, OfType = t3.OfType.Select((SchemaType t4) => new TypeModel { Kind = t4.Kind, Name = t4.Name, }).SingleOrDefault(), }).SingleOrDefault(), }).SingleOrDefault(), }).Single(), Args = f.Args.Select((InputValue a) => new InputValueModel { Name = a.Name, Description = a.Description, DefaultValue = a.DefaultValue, Type = a.Type.Select((SchemaType t1) => new TypeModel { Kind = t1.Kind, Name = t1.Name, OfType = t1.OfType.Select((SchemaType t2) => new TypeModel { Kind = t2.Kind, Name = t2.Name, OfType = t2.OfType.Select((SchemaType t3) => new TypeModel { Kind = t3.Kind, Name = t3.Name, OfType = t3.OfType.Select((SchemaType t4) => new TypeModel { Kind = t4.Kind, Name = t4.Name, }).SingleOrDefault(), }).SingleOrDefault(), }).SingleOrDefault(), }).Single(), }).ToList(), IsDeprecated = f.IsDeprecated, DeprecationReason = f.DeprecationReason, }).ToList(), EnumValues = t.EnumValues(true).Select((EnumValue e) => new EnumValueModel { Name = e.Name, Description = e.Description, IsDeprecated = e.IsDeprecated, DeprecationReason = e.DeprecationReason, }).ToList(), InputFields = t.InputFields.Select((InputValue i) => new InputValueModel { Name = i.Name, Description = i.Description, DefaultValue = i.DefaultValue, Type = i.Type.Select((SchemaType t1) => new TypeModel { Kind = t1.Kind, Name = t1.Name, OfType = t1.OfType.Select((SchemaType t2) => new TypeModel { Kind = t2.Kind, Name = t2.Name, OfType = t2.OfType.Select((SchemaType t3) => new TypeModel { Kind = t3.Kind, Name = t3.Name, OfType = t3.OfType.Select((SchemaType t4) => new TypeModel { Kind = t4.Kind, Name = t4.Name, }).SingleOrDefault(), }).SingleOrDefault(), }).SingleOrDefault(), }).Single(), }).ToList(), PossibleTypes = t.PossibleTypes.Select((SchemaType t1) => new TypeModel { Kind = t1.Kind, Name = t1.Name, Description = t1.Description, OfType = t1.OfType.Select((SchemaType t2) => new TypeModel { Kind = t2.Kind, Name = t2.Name, OfType = t2.OfType.Select((SchemaType t3) => new TypeModel { Kind = t3.Kind, Name = t3.Name, OfType = t3.OfType.Select((SchemaType t4) => new TypeModel { Kind = t4.Kind, Name = t4.Name, }).SingleOrDefault(), }).SingleOrDefault(), }).SingleOrDefault(), }).ToList(), }).ToList() }); return await connection.Run(query).ConfigureAwait(false); }
public void Select_Schema_Types() { var expectedQuery = @"{ __schema { types { kind name description fields(includeDeprecated: true) { name description type { name } } } } }"; var data = @"{ ""data"": { ""__schema"": { ""types"": [ { ""kind"": ""SCALAR"", ""name"": ""Scalar"", ""description"": ""A scalar value."", ""fields"": null }, { ""kind"": ""INPUT_OBJECT"", ""name"": ""InputObject"", ""description"": ""An input object."", ""fields"": null }, ] } } }"; var expression = new IntrospectionQuery() .Schema .Select(x => new SchemaModel { Types = x.Types.Select(t => new TypeModel { Kind = t.Kind, Name = t.Name, Description = t.Description, Fields = t.Fields(true).Select((Field f) => new FieldModel { Name = f.Name, Description = f.Description, Type = f.Type.Name, }).ToList() }).ToList() }); var query = new QueryBuilder().Build(expression); var queryResult = new QuerySerializer(2).Serialize(query.OperationDefinition); Assert.Equal(expectedQuery, queryResult); var responseResult = new ResponseDeserializer().Deserialize(query, data).Single(); var type = responseResult.Types[0]; Assert.Equal(TypeKind.Scalar, type.Kind); Assert.Equal("Scalar", type.Name); Assert.Equal("A scalar value.", type.Description); type = responseResult.Types[1]; Assert.Equal(TypeKind.InputObject, type.Kind); Assert.Equal("InputObject", type.Name); Assert.Equal("An input object.", type.Description); }