Exemplo n.º 1
0
        public ExecutionContext BuildExecutionContext(
            ISchema schema,
            object root,
            Document document,
            string operationName,
            Inputs inputs,
            CancellationToken cancellationToken)
        {
            var context = new ExecutionContext();
            context.Schema = schema;
            context.RootObject = root;

            var operation = !string.IsNullOrWhiteSpace(operationName)
                ? document.Operations.WithName(operationName)
                : document.Operations.FirstOrDefault();

            if (operation == null)
            {
                context.Errors.Add(new ExecutionError("Unknown operation name: {0}".ToFormat(operationName)));
                return context;
            }

            context.Operation = operation;
            context.Variables = GetVariableValues(schema, operation.Variables, inputs);
            context.Fragments = document.Fragments;
            context.CancellationToken = cancellationToken;

            return context;
        }
        public ValidationResult IsValid(Schema schema, Document document, string operationName)
        {
            var result = new ValidationResult();

            if (string.IsNullOrWhiteSpace(operationName)
                && document.Operations.Count() > 1)
            {
                result.Errors.Add(new ExecutionError("Must provide operation name if query contains multiple operations"));
            }

            return result;
        }
Exemplo n.º 3
0
        private Tuple<ExecutionContext, IEnumerable<ExecutionError>>  BuildExecutionContext(
            ISchema schema,
            object root,
            Document document,
            string operationName,
            Inputs inputs,
            CancellationToken cancellationToken,
            object userContext)
        {
            Operation operation = !string.IsNullOrWhiteSpace( operationName )
                ? document.Operations.WithName( operationName )
                : document.Operations.FirstOrDefault();

            ExecutionContext executionContext;
            if (operation == null)
            {
                IEnumerable<ExecutionError> executionErrors = new List<ExecutionError>
                {
                    new ExecutionError( string.Format( "Unknown operation name: {0}", operationName ) )
                };
                
                executionContext = new ExecutionContext(
                    schema,
                    root,
                    cancellationToken,
                    userContext);

                return new Tuple<ExecutionContext, IEnumerable<ExecutionError>>(
                    executionContext,
                    executionErrors );
            }

            executionContext = new ExecutionContext(
                schema,
                root,
                operation,
                document.Fragments,
                GetVariableValues(schema, operation.Variables, inputs),
                cancellationToken,
                userContext);

            return new Tuple<ExecutionContext, IEnumerable<ExecutionError>>(
                executionContext,
                null );
        }