示例#1
0
        public override object VisitOperationDefinition(GraphQLParser.OperationDefinitionContext context)
        {
            var operation = new Operation();

            NewNode(operation, context);

            operation.Name = context.NAME() != null?context.NAME().GetText() : "";

            operation.SelectionSet = Visit(context.selectionSet()) as SelectionSet;

            if (context.operationType() != null)
            {
                operation.OperationType = (OperationType)Enum.Parse(typeof(OperationType), context.operationType().GetText(), true);
            }

            if (context.variableDefinitions() != null)
            {
                operation.Variables = Visit(context.variableDefinitions()) as VariableDefinitions;
            }

            if (context.directives() != null)
            {
                operation.Directives = Visit(context.directives()) as Directives;
            }

            return(operation);
        }
示例#2
0
        protected Object ExtractAppropriateObjectForOperation(Object topLevelObject, GraphQLParser.OperationDefinitionContext context)
        {
            if (context.operationType().GetText().ToLower() == "mutation")
            {
                var property = topLevelObject.GetType().GetProperties()
                               .FirstOrDefault(x => x.GetCustomAttribute <GraphQlMutationsAttribute>() != null);
                if (property == null)
                {
                    Error($"Could not find an object with 'GraphQlMutationsAttribute' on property to support mutation - {context.NAME().GetText()}", context);
                }

                return(property.GetValue(topLevelObject));
            }
            else if (context.operationType().GetText().ToLower() == "query")
            {
                var property = topLevelObject.GetType().GetProperties()
                               .FirstOrDefault(x => x.GetCustomAttribute <GraphQlTopLevelQueryAttribute>() != null);
                if (property == null)
                {
                    Error($"Could not find an object with 'GraphQlQueryAttribute' on property to support query - {context.NAME().GetText()}", context);
                }

                return(property.GetValue(topLevelObject));
            }
            else
            {
                Error($"Unexpected operation type - expected 'query' or 'mutation' received - {context.operationType().GetText()}", context);
                return(null);
            }
        }
示例#3
0
 protected __Type ExtractAppropriate__TypeForOperation(__Schema schema, GraphQLParser.OperationDefinitionContext context)
 {
     if (context.operationType().GetText().ToLower() == "mutation")
     {
         return(schema.mutationType);
     }
     else if (context.operationType().GetText().ToLower() == "query")
     {
         return(schema.queryType);
     }
     else
     {
         Error($"Unexpected operation type - expected 'query' or 'mutation' received - {context.operationType().GetText()}", context);
         return(null);
     }
 }
示例#4
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="GraphQLParser.operationDefinition"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitOperationDefinition([NotNull] GraphQLParser.OperationDefinitionContext context)
 {
 }