public async Task Interface_With_Fragments() { // arrange var path = HotChocolate.Path.New("root"); DocumentNode document = Utf8GraphQLParser.Parse( FileResource.Open("Multiple_Fragments_Query.graphql")); var operation = document.Definitions .OfType <OperationDefinitionNode>() .First(); var field = operation.SelectionSet.Selections .OfType <FieldNode>() .First(); var query = new QueryDescriptor( "Simple_Query", "Foo.Bar.Ns", "1234", "12345", new byte[] { 1, 2, 3 }, document); var schema = SchemaBuilder.New() .AddDocumentFromString(FileResource.Open("StarWars.graphql")) .Use(next => context => Task.CompletedTask) .Create(); var context = new ModelGeneratorContext( schema, query, "StarWarsClient", "Foo.Bar.Ns"); var character = schema.GetType <InterfaceType>("Character"); // act var generator = new InterfaceModelGenerator(); generator.Generate( context, operation, character, character, field, context.CollectFields(character, field.SelectionSet, path), path); // assert var typeLookup = new TypeLookup( LanguageVersion.CSharp_8_0, CollectFieldsVisitor.MockLookup(document, context.FieldTypes), "Foo.Bar"); string output = await WriteAllAsync(context.Descriptors, typeLookup); output.MatchSnapshot(); }
private void GenerateFieldSelectionSet( OperationDefinitionNode operation, IType fieldType, FieldNode fieldSelection, Path path, Queue <FieldSelection> backlog) { var namedType = (INamedOutputType)fieldType.NamedType(); PossibleSelections possibleSelections = _fieldCollector.CollectFields( namedType, fieldSelection.SelectionSet !, path); foreach (SelectionInfo selectionInfo in possibleSelections.Variants) { EnqueueFields(backlog, selectionInfo.Fields, path); } if (namedType is UnionType unionType) { _unionModelGenerator.Generate( _context, operation, unionType, fieldType, fieldSelection, possibleSelections, path); } else if (namedType is InterfaceType interfaceType) { _interfaceModelGenerator.Generate( _context, operation, interfaceType, fieldType, fieldSelection, possibleSelections, path); } else if (namedType is ObjectType objectType) { _objectModelGenerator.Generate( _context, operation, objectType, fieldType, fieldSelection, possibleSelections, path); } }