private static bool IsSchemaOfCommonNames(IGraphQLSchema schema) { return ((schema.QueryType == null || schema.QueryType.Name == "Query") && (schema.MutationType == null || schema.MutationType.Name == "Mutation") && (schema.SubscriptionType == null || schema.SubscriptionType.Name == "Subscription")); }
public IEnumerable<GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new VariablesInAllowedPositionsVisitor(schema); visitor.Visit(document); return visitor.Errors; }
public IntrospectedSchemaType( ISchemaRepository schemaRepository, IGraphQLSchema schema) : base( "__Schema", "A GraphQL Schema defines the capabilities of a GraphQL server. It " + "exposes all available types and directives on the server, as well as " + "the entry points for query, mutation, and subscription operations.") { this.schemaRepository = schemaRepository; this.schema = schema; this.Field("types", () => this.IntrospectAllSchemaTypes()).WithDescription( "A list of all types supported by this server."); this.Field("queryType", () => this.IntrospectQueryType()).WithDescription( "The type that query operations will be rooted at."); this.Field("mutationType", () => this.IntrospectMutationType()).WithDescription( "If this server supports mutation, the type that " + "mutation operations will be rooted at."); this.Field("subscriptionType", () => this.IntrospectSubscriptionType()).WithDescription( "If this server support subscription, the type that " + "subscription operations will be rooted at."); this.Field("directives", () => this.IntrospectDirectives()).WithDescription( "A list of all directives supported by this server."); }
public IEnumerable <GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new SingleFieldSubscriptionsVisitor(schema); visitor.Visit(document); return(visitor.Errors); }
public NoFragmentCyclesVisitor(IGraphQLSchema schema) : base(schema) { this.Errors = new List <GraphQLException>(); this.visitedFragments = new List <string>(); this.spreadPath = new Stack <GraphQLFragmentSpread>(); this.spreadPathIndexByName = new Dictionary <string, int>(); this.fragmentDefinitions = new Dictionary <string, GraphQLFragmentDefinition>(); }
public IEnumerable <GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new FieldsOnCorrectTypeVisitor(schema); visitor.Visit(document); return(visitor.Errors); }
public IEnumerable <GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new KnownFragmentNamesVisitor(schema); visitor.Visit(document); return(visitor.Errors); }
public IEnumerable <GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new UniqueArgumentsVisitor(schema); visitor.Visit(document); return(visitor.Errors); }
public IEnumerable <GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new NoUndefinedVariablesVisitor(schema); visitor.Visit(document); return(visitor.Errors); }
public IEnumerable <GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new OverlappingFieldsCanBeMergedVisitor(schema); visitor.Visit(document); return(visitor.Errors); }
public IEnumerable <GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new UniqueDirectivesPerLocationVisitor(); visitor.Visit(document); return(visitor.Errors); }
public IEnumerable <GraphQLException> Validate(GraphQLDocument document, IGraphQLSchema schema) { var visitor = new LoneAnonymousOperationVisitor(schema); visitor.Visit(document); return(visitor.Errors); }
public static IEnumerable <VariableUsage> Get( GraphQLOperationDefinition operation, GraphQLDocument document, IGraphQLSchema schema) { var visitor = new VariableUsagesProvider(GetFragmentsFromDocument(document), schema); visitor.BeginVisitOperationDefinition(operation); return(visitor.variableUsages); }
public async Task Handle(WebSocket socket, string clientId, IGraphQLSchema schema, WsInputObject input) { await Task.Yield(); if (input.Id.HasValue) { schema.Unsubscribe(clientId, input.Id.Value); } }
public ValidationASTVisitor(IGraphQLSchema schema) { this.typeStack = new Stack <GraphQLBaseType>(); this.fieldStack = new Stack <GraphQLFieldInfo>(); this.Schema = schema; this.SchemaRepository = schema.SchemaRepository; this.LiteralValueValidator = new LiteralValueValidator(this.SchemaRepository); }
public ValidationASTVisitor(IGraphQLSchema schema) { this.Schema = schema; this.parentTypeStack = new Stack <GraphQLObjectType>(); this.typeStack = new Stack <GraphQLObjectType>(); this.fieldStack = new Stack <string>(); this.argumentTypes = new Dictionary <string, GraphQLScalarType>(); this.translator = schema.TypeTranslator; }
public async Task Handle(WebSocket socket, string clientId, IGraphQLSchema schema, WsInputObject input) { var dataString = schema == null ? CreateFailDataString(new GraphQLException("The server schema is invalid or does not exist.")) : CreateSuccessDataString(); var resultBuffer = System.Text.Encoding.UTF8.GetBytes(dataString); await socket.SendAsync( new ArraySegment <byte>(resultBuffer), WebSocketMessageType.Text, true, CancellationToken.None); }
private IEnumerable <string> GetSuggestedFieldNames(IGraphQLSchema schema, GraphQLBaseType type, string fieldName) { if (type is GraphQLObjectType || type is GraphQLInterfaceType) { var introspectedType = type.Introspect(schema.SchemaRepository); var possibleFieldNames = introspectedType.Value.Fields.Select(e => e.Value.Name.Value); return(StringUtils.SuggestionList(fieldName, possibleFieldNames)); } return(Enumerable.Empty <string>()); }
private static async Task Subscribe(WebSocket socket, string clientId, IGraphQLSchema schema, WsInputObject input) { var data = (IDictionary <string, object>)schema.Execute(input.Query, null, null, clientId, input.Id.Value); if (data.ContainsKey("errors")) { await SendResponseToExceptions(socket, input.Id.Value, data["errors"]); } else { var dataString = JsonConvert.SerializeObject(new { id = input.Id, type = "subscription_success" }); await SendResponse(socket, dataString); } }
public GraphQLException[] Validate( GraphQLDocument document, IGraphQLSchema schema, IValidationRule[] validationRules) { var errors = new List <GraphQLException>(); foreach (var rule in validationRules) { errors.AddRange(rule.Validate(document, schema)); } return(errors.ToArray()); }
public void SetUp() { this.variables = new ExpandoObject(); this.variables.intArgVar = 3; this.variables.stringArgVar = "sample"; this.variables.booleanArgVar = true; this.variables.enumArgVar = FurColor.BROWN; this.variables.enumArgVarAsString = "BROWN"; this.variables.floatArgVar = 1.6f; this.variables.stringListArgVar = new string[] { "a", "b", "c" }; this.variables.nonNullIntListArgVar = new int[] { 1, 2, 3 }; this.variables.intListArgVar = new int?[] { 1, null, 3 }; this.variables.complicatedObjectArgVar = CreateComplicatedDynamicObject(); this.variables.complicatedObjectArgVar.nested = CreateComplicatedDynamicObject(); this.schema = new TestSchema(); }
public IntrospectedSchemaType( ISchemaObserver schemaObserver, IIntrospector introspector, IGraphQLSchema schema) : base( "__Schema", "A GraphQL Schema defines the capabilities of a GraphQL server. It " + "exposes all available types and directives on the server, as well as " + "the entry points for query, mutation, and subscription operations.") { this.introspector = introspector; this.schemaObserver = schemaObserver; this.schema = schema; this.Field("types", () => this.Introspect()); this.Field("queryType", () => introspector.Introspect(this.schema.QueryType)); this.Field("mutationType", () => introspector.Introspect(this.schema.MutationType)); }
private IEnumerable <string> GetSuggestedTypeNames(IGraphQLSchema schema, GraphQLBaseType type, string fieldName) { var introspectedType = type.Introspect(schema.SchemaRepository); var suggestedObjectTypes = new List <string>(); var interfaceUsageCount = new Dictionary <string, int>(); if (introspectedType.Value.PossibleTypes == null) { return(suggestedObjectTypes); } foreach (var possibleType in introspectedType.Value.PossibleTypes) { if (possibleType.Value.Fields.Any(e => e.Value.Name == fieldName)) { suggestedObjectTypes.Add(possibleType.Value.Name); foreach (var possibleInterface in possibleType.Value.Interfaces) { if (possibleInterface.Value.Fields.Any(e => e.Value.Name == fieldName)) { if (!interfaceUsageCount.ContainsKey(possibleInterface.Value.Name)) { interfaceUsageCount.Add(possibleInterface.Value.Name, 1); } else { interfaceUsageCount[possibleInterface.Value.Name]++; } } } } } var suggestedInterfaceTypes = interfaceUsageCount.OrderByDescending(e => e.Value).Select(e => e.Key); return(suggestedInterfaceTypes.Concat(suggestedObjectTypes)); }
private static string PrintSchemaDefinition(IGraphQLSchema schema) { var operationTypes = new List <string>(); if (IsSchemaOfCommonNames(schema)) { return(null); } if (schema.QueryType != null) { operationTypes.Add($" query: {schema.QueryType.Name}"); } if (schema.MutationType != null) { operationTypes.Add($" mutation: {schema.MutationType.Name}"); } if (schema.SubscriptionType != null) { operationTypes.Add($" subscription: {schema.SubscriptionType.Name}"); } return($"schema {{\n{string.Join("\n", operationTypes)}\n}}"); }
public DefaultValuesOfCorrectTypeVisitor(IGraphQLSchema schema) : base(schema) { this.Errors = new List <GraphQLException>(); }
public ScalarLeafsVisitor(IGraphQLSchema schema) : base(schema) { this.Errors = new List <GraphQLException>(); }
public KnownFragmentNamesVisitor(IGraphQLSchema schema) { this.Errors = new List <GraphQLException>(); this.fragmentDefinitions = new Dictionary <string, GraphQLFragmentDefinition>(); }
public async Task Handle(WebSocket socket, string clientId, IGraphQLSchema schema, WsInputObject input) { await Subscribe(socket, clientId, schema, input); }
public static string PrintSchema(IGraphQLSchema schema) { var printer = new SchemaPrinter(schema); return(printer.PrintSchema()); }
public LoneAnonymousOperationVisitor(IGraphQLSchema schema) : base(schema) { this.Errors = new List <GraphQLException>(); }