public void DeserializeStarWarsIntrospectionResult() { // arrange string json = FileResource.Open("StarWarsIntrospectionResult.json"); IntrospectionResult result = JsonSerializer.Deserialize <IntrospectionResult>( json, IntrospectionClient.SerializerOptions); // act DocumentNode schema = IntrospectionDeserializer.Deserialize(result); // assert schema.ToString(true).MatchSnapshot(); }
public void DeserializeIntrospectionWithIntDefaultValues() { // arrange string json = FileResource.Open("IntrospectionWithDefaultValues.json"); IntrospectionResult result = JsonSerializer.Deserialize <IntrospectionResult>( json, IntrospectionClient.SerializerOptions); // act DocumentNode schema = IntrospectionDeserializer.Deserialize(result); // assert SchemaSyntaxSerializer.Serialize(schema).MatchSnapshot(); }
public static DocumentNode Deserialize(IntrospectionResult result) { var typeDefinitions = new List <IDefinitionNode>(); typeDefinitions.Add(CreateSchema(result.Data.Schema)); typeDefinitions.AddRange(CreateTypes(result.Data.Schema.Types)); foreach (Directive directive in result.Data.Schema.Directives) { DirectiveDefinitionNode directiveDefinition = CreateDirectiveDefinition(directive); if (directiveDefinition.Locations.Any()) { typeDefinitions.Add(directiveDefinition); } } return(new DocumentNode(typeDefinitions)); }
public async Task <ISchemaFeatures> GetSchemaFeaturesAsync( HttpClient client, CancellationToken cancellationToken = default) { if (client is null) { throw new ArgumentNullException(nameof(client)); } HttpQueryRequest request = IntrospectionQueryHelper.CreateFeatureQuery(); IntrospectionResult result = await ExecuteIntrospectionAsync( client, request, cancellationToken) .ConfigureAwait(false); EnsureNoGraphQLErrors(result); return(SchemaFeatures.FromIntrospectionResult(result)); }
internal static SchemaFeatures FromIntrospectionResult( IntrospectionResult result) { var features = new SchemaFeatures(); FullType directive = result.Data.Schema.Types.First(t => t.Name.Equals(_directiveName, StringComparison.Ordinal)); features.HasRepeatableDirectives = directive.Fields.Any(t => t.Name.Equals(_isRepeatable, StringComparison.Ordinal)); features.HasDirectiveLocations = directive.Fields.Any(t => t.Name.Equals(_locations, StringComparison.Ordinal)); FullType schema = result.Data.Schema.Types.First(t => t.Name.Equals(_schemaName, StringComparison.Ordinal)); features.HasSubscriptionSupport = schema.Fields.Any(t => t.Name.Equals(_subscriptionType, StringComparison.Ordinal)); return(features); }
public async Task <DocumentNode> DownloadSchemaAsync( HttpClient client, CancellationToken cancellationToken = default) { if (client is null) { throw new ArgumentNullException(nameof(client)); } ISchemaFeatures features = await GetSchemaFeaturesAsync( client, cancellationToken) .ConfigureAwait(false); HttpQueryRequest request = IntrospectionQueryHelper.CreateIntrospectionQuery(features); IntrospectionResult result = await ExecuteIntrospectionAsync( client, request, cancellationToken) .ConfigureAwait(false); EnsureNoGraphQLErrors(result); return(IntrospectionDeserializer.Deserialize(result).RemoveBuiltInTypes()); }
private void EnsureNoGraphQLErrors(IntrospectionResult result) { if (result.Errors is { })