private static void VisitOperationSelectionSet( IDocumentAnalyzerContext context, OperationDefinitionNode operation, ObjectType operationType, Path path, Queue <FieldSelection> backlog) { PossibleSelections possibleSelections = context.CollectFields( operationType, operation.SelectionSet, path); EnqueueFields(backlog, possibleSelections.ReturnType.Fields, path); _objectTypeSelectionSetAnalyzer.Analyze( context, operation, new FieldNode( null, new NameNode(operation.Name !.Value), null, new[] { new DirectiveNode( GeneratorDirectives.Type, new ArgumentNode("name", operation.Name.Value)), new DirectiveNode(GeneratorDirectives.Operation) }, Array.Empty <ArgumentNode>(), null), possibleSelections, new NonNullType(operationType), operationType, path); }
public void Simple_Object_Selection_With_Alias() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType <Query>() .Create(); DocumentNode document = Utf8GraphQLParser.Parse("{ foo { b: bar { baz } } }"); OperationDefinitionNode operation = document.Definitions.OfType <OperationDefinitionNode>().Single(); FieldNode field = operation.SelectionSet.Selections.OfType <FieldNode>().Single(); var context = new DocumentAnalyzerContext(schema); context.SetDocument(document); ObjectType fooType = schema.GetType <ObjectType>("Foo"); Path rootPath = Path.New("foo"); PossibleSelections possibleSelections = context.CollectFields( fooType, field.SelectionSet, rootPath); // act var analyzer = new ObjectTypeSelectionSetAnalyzer(); analyzer.Analyze( context, operation, field, possibleSelections, schema.QueryType.Fields["foo"].Type, fooType, rootPath); // assert Assert.Collection(context.Types.OfType <ComplexOutputTypeModel>(), type => { Assert.Equal("Foo", type.Name); Assert.Null(type.Description); Assert.Equal(fooType, type.Type); Assert.Equal(field.SelectionSet, type.SelectionSet); Assert.Empty(type.Types); Assert.Collection(type.Fields, field => { Assert.Equal("B", field.Name); Assert.Null(field.Description); Assert.Equal(fooType.Fields["bar"], field.Field); Assert.Equal(fooType.Fields["bar"].Type, field.Type); Assert.Equal(rootPath.Append("b"), field.Path); }); }); }