public string Format(IGraphSchema schema, GraphSchemaFormat format) { Guard.ArgumentNotNull(schema, nameof(schema)); if (null != _formatted) { return(_formatted); } _formatted = format == GraphSchemaFormat.GQL ? FormatAsGql(schema) : FormatAsInline(schema); return(_formatted); }
public SelectionSetProvider( IGraphTypeProvider graphTypeProvider, IGraphSchemaProvider schemaProvider, IQueryResultTypeGenerator typeGenerator, ILogger <SelectionSetProvider> logger, IOptions <GraphOptions> optionsAccessor) { Guard.ArgumentNotNull(schemaProvider, nameof(schemaProvider)); _graphTypeProvider = graphTypeProvider ?? throw new ArgumentNullException(nameof(graphTypeProvider)); _selections = new ConcurrentDictionary <string, ICollection <ISelectionNode> >(); _typeGenerator = Guard.ArgumentNotNull(typeGenerator, nameof(typeGenerator)); _schema = schemaProvider.Schema; _fieldNameConverter = Guard.ArgumentNotNull(optionsAccessor, nameof(optionsAccessor)).Value.FieldNameConverter; _logger = Guard.ArgumentNotNull(logger, nameof(logger)); _log4MissCache = LoggerMessage.Define <DateTimeOffset, string, string>(LogLevel.Trace, 0, "[{0}]Selection set cache missing. Operation: {1}; Reason: {2}."); }
public GraphQLNetSchema Convert(IGraphSchema graphSchema) { var schema = new GraphQLNetSchema(); if (schema.Query.Fields.Any()) { schema.Query = (IObjectGraphType)Convert(graphSchema.Query); } if (schema.Mutation.Fields.Any()) { schema.Mutation = (IObjectGraphType)Convert(graphSchema.Mutation); } if (schema.Subscription.Fields.Any()) { schema.Subscription = (IObjectGraphType)Convert(graphSchema.Subscription); } return(schema); }
public ISchema Convert(IGraphSchema graphSchema) { var schema = new Schema(); if (graphSchema.Query.Fields.Any()) { schema.Query = CreateSchema(OperationType.Query, graphSchema.Query, schema); } if (graphSchema.Mutation.Fields.Any()) { schema.Mutation = CreateSchema(OperationType.Mutation, graphSchema.Mutation, schema); } if (graphSchema.Subscription.Fields.Any()) { schema.Subscription = CreateSchema(OperationType.Subscription, graphSchema.Subscription, schema); } return(schema); }
public GraphQLNetSchema Convert(IGraphSchema graphSchema) { var schema = new GraphQLNetSchema(); if (graphSchema.Query.Fields.Any()) { schema.Query = CreateSchema(OperationType.Query, graphSchema.Query); schema.RegisterType(schema.Query); } if (graphSchema.Mutation.Fields.Any()) { schema.Mutation = CreateSchema(OperationType.Mutation, graphSchema.Mutation); } if (graphSchema.Subscription.Fields.Any()) { schema.Subscription = CreateSchema(OperationType.Subscription, graphSchema.Subscription); } return(schema); }
private string FormatAsGql(IGraphSchema graphSchema) { var types = new List <IGraphType>(); CollectGraphTypes(new HashSet <string>(), types, graphSchema); var builder = new StringBuilder(); var root = types.Single(it => it.Name == "GraphQL"); WriteAsGQL(builder, root); types.Remove(root); var query = types.SingleOrDefault(it => it.Name == "Query"); if (null != query) { WriteAsGQL(builder, query); types.Remove(query); } var mutation = types.SingleOrDefault(it => it.Name == "Mutation"); if (null != mutation) { WriteAsGQL(builder, mutation); types.Remove(mutation); } var subscription = types.SingleOrDefault(it => it.Name == "Subscription"); if (null != subscription) { WriteAsGQL(builder, subscription); types.Remove(subscription); } foreach (var type in types) { WriteAsGQL(builder, type); } return(builder.ToString()); }
private string FormatAsInline(IGraphSchema graphSchema) { var builder = new StringBuilder(); if (graphSchema.Query.Fields.Any()) { builder.AppendLine("Query"); WriteAsInline(builder, 1, graphSchema.Query); } if (graphSchema.Mutation.Fields.Any()) { builder.AppendLine("Mutation"); WriteAsInline(builder, 1, graphSchema.Mutation); } if (graphSchema.Subscription.Fields.Any()) { builder.AppendLine("Subsription"); WriteAsInline(builder, 1, graphSchema.Subscription); } return(builder.ToString()); }