Beispiel #1
0
        /// <summary>
        /// Parses a fragment definition.
        /// <see cref="FragmentDefinitionNode" />:
        /// fragment FragmentName on TypeCondition Directives? SelectionSet
        /// </summary>
        /// <param name="context">The parser context.</param>
        private static FragmentDefinitionNode ParseFragmentDefinition(
            ParserContext context)
        {
            SyntaxToken start = context.Current;

            context.ExpectFragmentKeyword();

            // Experimental support for defining variables within fragments
            // changesthe grammar of FragmentDefinition:
            // fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
            if (context.Options.Experimental.AllowFragmentVariables)
            {
                NameNode name = ParseFragmentName(context);
                List <VariableDefinitionNode> variableDefinitions =
                    ParseVariableDefinitions(context);
                context.ExpectOnKeyword();
                NamedTypeNode        typeCondition = ParseNamedType(context);
                List <DirectiveNode> directives    =
                    ParseDirectives(context, false);
                SelectionSetNode selectionSet = ParseSelectionSet(context);
                Location         location     = context.CreateLocation(start);

                return(new FragmentDefinitionNode
                       (
                           location,
                           name,
                           variableDefinitions,
                           typeCondition,
                           directives,
                           selectionSet
                       ));
            }
            else
            {
                NameNode name = ParseFragmentName(context);
                context.ExpectOnKeyword();
                NamedTypeNode        typeCondition = ParseNamedType(context);
                List <DirectiveNode> directives    =
                    ParseDirectives(context, false);
                SelectionSetNode selectionSet = ParseSelectionSet(context);
                Location         location     = context.CreateLocation(start);

                return(new FragmentDefinitionNode
                       (
                           location,
                           name,
                           Array.Empty <VariableDefinitionNode>(),
                           typeCondition,
                           directives,
                           selectionSet
                       ));
            }
        }