public void ParallelAttributeWillBeHonored(ExecutionStrategy defaultStrategy) { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <ParallelQuery>() .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"{ foo }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.QueryType, new(new DefaultTypeConverter())); // act QueryPlanNode root = QueryPlanBuilder.Prepare(operation); // assert Snapshot(root, defaultStrategy); }
public void ExtendedRootTypesWillHonorGlobalSerialSetting(ExecutionStrategy defaultStrategy) { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(c => c.Name(OperationTypeNames.Query)) .AddType <BarQueries>() .ModifyOptions(o => o.DefaultResolverStrategy = defaultStrategy) .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"{ bars }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.QueryType, new(new DefaultTypeConverter())); // act QueryPlanNode root = QueryPlanBuilder.Prepare(operation); // assert Snapshot(root, defaultStrategy); }
public void CreateReviewForEpisode_Plan(ExecutionStrategy defaultStrategy) { // arrange ISchema schema = SchemaBuilder.New() .AddStarWarsTypes() .ModifyOptions(o => o.DefaultResolverStrategy = defaultStrategy) .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"mutation CreateReviewForEpisode( $ep: Episode!, $review: ReviewInput!) { createReview(episode: $ep, review: $review) { stars commentary } }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.MutationType !, new(new DefaultTypeConverter())); // act QueryPlanNode root = QueryPlanBuilder.Prepare(operation); // assert Snapshot(root, defaultStrategy); }
public void Optimize(IPreparedOperation operation, ObjectType objectType) { Visit( new OptimizerContext(operation), operation.GetRootSelectionSet(), null); }
public static QueryPlanNode Prepare(IPreparedOperation operation) { if (operation is null) { throw new ArgumentNullException(nameof(operation)); } return(Prepare(new QueryPlanContext(operation))); }
public bool CanHandleSelections( IPreparedOperation operation, ISelectionSet selectionSet, IObjectType objectType, out IReadOnlyList <ISelection> handledSelections) { var context = new MatchSelectionsContext(_schema, operation, selection); _matchSelections.Visit(Provides, context); }
public void Prepare_Inline_Fragment() { // arrange ISchema schema = SchemaBuilder.New() .AddStarWarsTypes() .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"{ hero(episode: EMPIRE) { name ... on Droid { primaryFunction } ... on Human { homePlanet } } }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); // act IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.QueryType, new(new DefaultTypeConverter())); // assert ISelection hero = operation.GetRootSelectionSet().Selections.Single(); Assert.Equal("hero", hero.ResponseName); Assert.Collection( operation.GetSelectionSet(hero.SelectionSet !, schema.GetType <ObjectType>("Droid")) .Selections, selection => Assert.Equal("name", selection.ResponseName), selection => Assert.Equal("primaryFunction", selection.ResponseName)); Assert.Collection( operation.GetSelectionSet(hero.SelectionSet, schema.GetType <ObjectType>("Human")) .Selections, selection => Assert.Equal("name", selection.ResponseName), selection => Assert.Equal("homePlanet", selection.ResponseName)); operation.Print().MatchSnapshot(); }
private MatchSelectionsContext( ISchema schema, IPreparedOperation operation, IReadOnlyDictionary <string, ISelection[]> selections, IImmutableStack <IOutputType> types, Counter counter) { Schema = schema; Operation = operation; Selections = selections; Types = types; _counter = counter; }
public MatchSelectionsContext( ISchema schema, IPreparedOperation operation, ISelectionSet selection, IObjectType objectType) { Schema = schema; Operation = operation; Selections = selection.Selections .GroupBy(t => t.Field.Name.Value) .ToDictionary(t => t.Key, t => t.ToArray()); Types = ImmutableStack <IOutputType> .Empty.Push(objectType); _counter = new Counter(); }
public void GetHero_Root_Deferred_Plan(ExecutionStrategy defaultStrategy) { // arrange ISchema schema = SchemaBuilder.New() .AddStarWarsTypes() .ModifyOptions(o => o.DefaultResolverStrategy = defaultStrategy) .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"query GetHero($episode: Episode, $withFriends: Boolean!) { ... @defer { hero(episode: $episode) { name friends @include(if: $withFriends) { nodes { id } } } } a: hero(episode: $episode) { name friends @include(if: $withFriends) { nodes { id } } } }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.QueryType, new(new DefaultTypeConverter())); // act QueryPlanNode root = QueryPlanBuilder.Prepare(operation); // assert Snapshot(root, defaultStrategy); }
public void GetHero_Stream_Plan_Nested_Streams(ExecutionStrategy defaultStrategy) { // arrange ISchema schema = SchemaBuilder.New() .AddStarWarsTypes() .ModifyOptions(o => o.DefaultResolverStrategy = defaultStrategy) .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"{ hero(episode: NEW_HOPE) { id ... @defer(label: ""friends"") { friends { nodes @stream(initialCount: 1) { id name friends { nodes @stream(initialCount: 1) { id name } } } } } } }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.QueryType, new(new DefaultTypeConverter())); // act QueryPlanNode root = QueryPlanBuilder.Prepare(operation); // assert Snapshot(root, defaultStrategy); }
public static QueryPlan Build(IPreparedOperation operation) { if (operation is null) { throw new ArgumentNullException(nameof(operation)); } var context = new QueryPlanContext(operation); OperationNode operationNode = Prepare(context); QueryPlan[] deferredPlans = operationNode.Deferred.Count > 0 ? new QueryPlan[operationNode.Deferred.Count] : Array.Empty <QueryPlan>(); Dictionary <int, QueryPlan>?streamPlans = context.Streams.Count > 0 ? new Dictionary <int, QueryPlan>() : null; if (operationNode.Deferred.Count > 0) { for (var i = 0; i < operationNode.Deferred.Count; i++) { deferredPlans[i] = new QueryPlan( operationNode.Deferred[i].CreateStep(), deferredPlans, streamPlans); } } if (context.Streams.Count > 0) { foreach (StreamPlanNode streamPlanNode in context.Streams.Values) { var streamPlan = new QueryPlan( streamPlanNode.Root.CreateStep(), deferredPlans, streamPlans); streamPlans !.Add(streamPlanNode.Id, streamPlan); } } return(new QueryPlan(operationNode.CreateStep(), deferredPlans, streamPlans)); }
public void TypeNameFieldsInMutations() { // arrange ISchema schema = SchemaBuilder.New() .AddDocumentFromString(@" type Query { foo: String } type Mutation { bar: Bar } type Bar { test: String } ") .Use(next => next) .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"mutation { bar { test __typename } }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.MutationType !, new(new DefaultTypeConverter())); // act QueryPlanNode root = QueryPlanBuilder.Prepare(operation); // assert Snapshot(root); }
public void Initialize( IRequestContext requestContext, IServiceProvider scopedServices, IBatchDispatcher batchDispatcher, IPreparedOperation operation, object?rootValue, IVariableValueCollection variables) { _requestContext = requestContext; _executionContext.Initialize( batchDispatcher, requestContext.RequestAborted); Operation = operation; RootValue = rootValue; Variables = variables; Services = scopedServices; }
public void Prepare_Fragment_Definition() { // arrange ISchema schema = SchemaBuilder.New() .AddStarWarsTypes() .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"{ hero(episode: EMPIRE) { name ... abc ... def } } fragment abc on Droid { primaryFunction } fragment def on Human { homePlanet } "); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); // act IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.QueryType, new(new DefaultTypeConverter())); // assert operation.Print().MatchSnapshot(); }
public void Prepare_Duplicate_Field_With_Skip() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(c => c .Name("Query") .Field("foo") .Type <StringType>() .Resolve("foo")) .Create(); DocumentNode document = Utf8GraphQLParser.Parse("{ foo @skip(if: true) foo @skip(if: false) }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); // act IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.QueryType, new(new DefaultTypeConverter())); // assert Assert.Collection( operation.SelectionVariants, selectionSet => { Assert.Equal(operationDefinition.SelectionSet, selectionSet.SelectionSet); Assert.Collection( selectionSet.GetSelectionSet(schema.QueryType).Selections, selection => Assert.Equal("foo", selection.ResponseName)); }); }
public void Reuse_Selection() { // arrange ISchema schema = SchemaBuilder.New() .AddStarWarsTypes() .Create(); DocumentNode document = Utf8GraphQLParser.Parse( @"query Hero($episode: Episode, $withFriends: Boolean!) { hero(episode: $episode) { name friends @include(if: $withFriends) { nodes { id } } } }"); OperationDefinitionNode operationDefinition = document.Definitions.OfType <OperationDefinitionNode>().Single(); // act IPreparedOperation operation = OperationCompiler.Compile( "a", document, operationDefinition, schema, schema.QueryType, new(new DefaultTypeConverter())); // assert operation .Print() .MatchSnapshot(); }
public void TryAddOperation( string operationId, IPreparedOperation operation) => _cache.GetOrCreate(operationId, () => operation);
public QueryPlanContext(IPreparedOperation operation) { Operation = operation; }
public OptimizerContext(IPreparedOperation operation) { Operation = operation; Processed = new HashSet <ISelection>(); QueryPlan = new List <FetchTask>(); }