示例#1
0
    ResolveFieldContext ResolveFieldContext(
        MyDataContext ctx,
        CancellationToken token,
        Document document,
        ISchema schema)
    {
        var operation        = document.Operations.FirstOrDefault();
        var variableValues   = ExecutionHelper.GetVariableValues(document, schema, operation?.Variables, null);
        var executionContext = new ExecutionContext
        {
            Document                  = document,
            Schema                    = schema,
            UserContext               = ctx,
            Variables                 = variableValues,
            Fragments                 = document.Fragments,
            CancellationToken         = token,
            Listeners                 = new IDocumentExecutionListener[0],
            Operation                 = operation,
            ThrowOnUnhandledException = true // DEBUG
        };

        var operationRootType = ExecutionHelper.GetOperationRootType(
            executionContext.Document,
            executionContext.Schema,
            executionContext.Operation);

        var node = ExecutionStrategy.BuildExecutionRootNode(executionContext, operationRootType);

        return(GetContext(executionContext, node.SubFields["companies"]));
    }
示例#2
0
        private bool SkipAuthCheck(Field field, ValidationContext context)
        {
            if (field.Directives == null || !field.Directives.Any())
            {
                return(false);
            }

            var operationName      = context.OperationName;
            var documentOperations = context.Document.Operations;
            var operation          = !string.IsNullOrWhiteSpace(operationName)
                ? documentOperations.WithName(operationName)
                : documentOperations.FirstOrDefault();
            var variables = ExecutionHelper.GetVariableValues(context.Document, context.Schema,
                                                              operation?.Variables, context.Inputs);

            var includeField = GetDirectiveValue(context, field.Directives, DirectiveGraphType.Include, variables);

            if (includeField.HasValue)
            {
                return(!includeField.Value);
            }

            var skipField = GetDirectiveValue(context, field.Directives, DirectiveGraphType.Skip, variables);

            if (skipField.HasValue)
            {
                return(skipField.Value);
            }

            return(false);
        }
        public INodeVisitor Validate(ValidationContext context)
        {
            var variableValues = new Lazy <Variables>(() => ExecutionHelper.GetVariableValues(
                                                          context.Document,
                                                          context.Schema,
                                                          context.TypeInfo.GetAncestors().OfType <Operation>().First().Variables,
                                                          context.Inputs));

            return(new EnterLeaveListener(listener =>
            {
                // match a node type, arguments are considered a node the same as everything else in the query.
                listener.Match <Argument>(arg =>
                                          ((GraphQLUserContext)context.UserContext).RequestedProductIds.UnionWith(GetProductIdsFromArgs(new Arguments {
                    arg
                }, context, variableValues)));
            }
                                          ));
        }
示例#4
0
 public Language.AST.Variables ParseVariables()
 {
     return(Inputs == null ? null : ExecutionHelper.GetVariableValues(Document, Schema, Operation.Variables, Inputs));
 }