示例#1
0
        private static void VisitFieldSelectionSet(
            IDocumentAnalyzerContext context,
            OperationDefinitionNode operation,
            FieldNode fieldSelection,
            IType fieldType,
            Path path,
            Queue <FieldSelection> backlog)
        {
            var namedType = (INamedOutputType)fieldType.NamedType();

            PossibleSelections possibleSelections =
                context.CollectFields(
                    namedType,
                    fieldSelection.SelectionSet !,
                    path);

            foreach (SelectionInfo selectionInfo in possibleSelections.Variants)
            {
                EnqueueFields(backlog, selectionInfo.Fields, path);
            }

            if (namedType is UnionType unionType)
            {
                _unionTypeSelectionSetAnalyzer.Analyze(
                    context,
                    operation,
                    fieldSelection,
                    possibleSelections,
                    fieldType,
                    unionType,
                    path);
            }
            else if (namedType is InterfaceType interfaceType)
            {
                _interfaceTypeSelectionSetAnalyzer.Analyze(
                    context,
                    operation,
                    fieldSelection,
                    possibleSelections,
                    fieldType,
                    interfaceType,
                    path);
            }
            else if (namedType is ObjectType objectType)
            {
                _objectTypeSelectionSetAnalyzer.Analyze(
                    context,
                    operation,
                    fieldSelection,
                    possibleSelections,
                    fieldType,
                    objectType,
                    path);
            }
        }
示例#2
0
        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);
        }