Пример #1
0
        private static bool GetIfArgumentValue(
            ISchema schema,
            GraphQLDirective directive,
            Dictionary <string, object> coercedVariableValues,
            GraphQLArgument argument)
        {
            if (directive == null)
            {
                throw new ArgumentNullException(nameof(directive));
            }
            if (coercedVariableValues == null)
            {
                throw new ArgumentNullException(nameof(coercedVariableValues));
            }
            if (argument == null)
            {
                throw new GraphQLError(
                          "Directive is missing argument which is required", directive);
            }

            switch (argument.Value)
            {
            case GraphQLScalarValue scalarValue:
                return((bool)Values.CoerceValue(schema.GetInputFields, scalarValue, ScalarType.NonNullBoolean));

            case GraphQLVariable variable:
                var variableValue = coercedVariableValues[variable.Name.Value];
                return((bool)variableValue);

            default:
                return(false);
            }
        }
        public Directive Directive(GraphQLDirective d)
        {
            var dir = new Directive(Name(d.Name)).WithLocation(d, _body);

            dir.Arguments = Arguments(d.Arguments);
            return(dir);
        }
Пример #3
0
        private string PrintDirective(GraphQLDirective directive)
        {
            var name = PrintName(directive.Name);
            var args = directive.Arguments?.Select(PrintArgument);

            return($"@{name}{Wrap("(", Join(args, ", "), ")")}");
        }
Пример #4
0
 public virtual bool PostExecutionIncludeFieldIntoResult(
     GraphQLDirective directive,
     ISchemaRepository schemaRepository,
     object value,
     object parentValue)
 {
     return(true);
 }
Пример #5
0
        public override GraphQLDirective BeginVisitDirective(GraphQLDirective directive)
        {
            Tracker.EnterDirective?.Invoke(directive);

            var _ = base.BeginVisitDirective(directive);

            Tracker.LeaveDirective?.Invoke(_);
            return(_);
        }
Пример #6
0
        private List <GraphQLArgument> GetArgumentsFromDirectiveDefinition(GraphQLDirective directive,
                                                                           GraphQLDirectiveType directiveInfo)
        {
            if (directiveInfo == null || directiveInfo.Arguments?.Count == 0)
            {
                return(null);
            }

            return(this.MergeArgumentsWithDefault(directive.Arguments, directiveInfo.Arguments));
        }
        public override bool PreExecutionIncludeFieldIntoResult(
            GraphQLDirective directive,
            ISchemaRepository schemaRepository)
        {
            var argument    = directive.Arguments.Single(e => e.Name.Value == "if");
            var booleanType = new GraphQLBoolean();

            var result = booleanType.GetFromAst(argument.Value, schemaRepository);

            return(!(bool)result.Value);
        }
Пример #8
0
        private static bool SkipSelection(GraphQLDirective skipDirective,
                                          Dictionary <string, object> coercedVariableValues, ISchema schema, ObjectType objectType, ASTNode selection)
        {
            if (skipDirective == null)
            {
                return(false);
            }

            var ifArgument = skipDirective.Arguments.SingleOrDefault(a => a.Name?.Value == "if");

            return(GetIfArgumentValue(schema, skipDirective, coercedVariableValues, ifArgument));
        }
Пример #9
0
        private static bool IncludeSelection(GraphQLDirective includeDirective,
                                             IReadOnlyDictionary <string, object> coercedVariableValues, ISchema schema, ObjectType objectType, ASTNode selection)
        {
            if (includeDirective == null)
            {
                return(true);
            }

            var ifArgument = includeDirective.Arguments.SingleOrDefault(a => a.Name?.Value == "if");

            return(GetIfArgumentValue(schema, includeDirective, coercedVariableValues, ifArgument));
        }
Пример #10
0
 public virtual GraphQLDirective BeginVisitDirective(GraphQLDirective directive)
 {
     if (directive.Name != null)
     {
         BeginVisitNode(directive.Name);
     }
     if (directive.Arguments != null)
     {
         BeginVisitArguments(directive.Arguments);
     }
     return(directive);
 }
Пример #11
0
        private string PrintDirective(GraphQLDirective directive)
        {
            var name = this.PrintName(directive.Name);

            if (directivesToRemove.Contains(name))
            {
                return(string.Empty);
            }

            var args = directive.Arguments?.Select(this.PrintArgument);

            return($"@{name}{this.Wrap("(", this.Join(args, ", "), ")")}");
        }
        public virtual GraphQLDirective BeginVisitDirective(GraphQLDirective directive)
        {
            if (directive.Name != null)
            {
                this.BeginVisitNode(directive.Name);
            }

            if (directive.Arguments != null)
            {
                this.BeginVisitNodeCollection(directive.Arguments);
            }

            return(this.EndVisitDirective(directive));
        }
        private void ValidateDirectiveArgument(
            GraphQLDirective directive,
            GraphQLObjectTypeArgumentInfo argument,
            IEnumerable <GraphQLArgument> providedArguments)
        {
            var providedArgument = providedArguments.FirstOrDefault(e => e.Name.Value == argument.Name);
            var argumentType     = argument.GetGraphQLType(this.SchemaRepository);

            if (providedArgument == null && argumentType is GraphQLNonNull)
            {
                this.Errors.Add(
                    new GraphQLException(
                        $"Directive \"{directive.Name.Value}\" argument \"{argument.Name}\" of type \"{argumentType}\" is required but not provided.",
                        new[] { directive }));
            }
        }
        public override GraphQLDirective EndVisitDirective(GraphQLDirective directive)
        {
            var directiveDefinition = this.schemaRepository.GetDirective(directive.Name.Value);

            if (directiveDefinition != null)
            {
                var definedArguments = directiveDefinition.GetArguments();

                foreach (var argument in definedArguments)
                {
                    this.ValidateDirectiveArgument(directive, argument, directive.Arguments);
                }
            }

            return(base.EndVisitDirective(directive));
        }
Пример #15
0
        public override GraphQLDirective BeginVisitDirective(GraphQLDirective directive)
        {
            var directiveDefinition = this.schemaRepository.GetDirective(directive.Name.Value);

            if (directiveDefinition == null)
            {
                var errorMessage = this.ComposeUnknownDirectiveMessage(directive.Name.Value);

                this.Errors.Add(new GraphQLException(errorMessage, new[] { directive }));
            }
            else
            {
                var candidateLocation = this.GetDirectiveLocationForAstPath();

                if (!directiveDefinition.Locations.Contains(candidateLocation))
                {
                    var errorMessage = this.ComposeMisplacedDirectiveMessage(directive.Name.Value, candidateLocation.ToString());
                    this.Errors.Add(new GraphQLException(errorMessage, new[] { directive }));
                }
            }

            return(base.BeginVisitDirective(directive));
        }
 /// <summary>
 /// Initializes a new instance with the specified properties.
 /// </summary>
 public DirectivesInAllowedLocationsError(ValidationContext context, GraphQLDirective node, DirectiveLocation candidateLocation)
     : base(context.Document.Source, "5.7.2", $"Directive '{node.Name}' may not be used on {candidateLocation}.", node)
 {
 }
Пример #17
0
 public string PrintAstDirective(GraphQLDirective directive) => AstPrinter.Print(CoreToVanillaConverter.Directive(directive));
Пример #18
0
 public virtual bool PreExecutionIncludeFieldIntoResult(
     GraphQLDirective directive, ISchemaRepository schemaRepository)
 {
     return(true);
 }
        public override GraphQLDirective EndVisitDirective(GraphQLDirective directive)
        {
            this.directive = null;

            return(base.EndVisitDirective(directive));
        }
 /// <summary>
 /// Initializes a new instance with the specified properties.
 /// </summary>
 public UniqueDirectivesPerLocationError(ValidationContext context, GraphQLDirective node)
     : base(context.Document.Source, NUMBER, $"The directive '{node.Name}' can only be used once at this location.", node)
 {
 }
Пример #21
0
 // https://github.com/graphql/graphql-spec/issues/632
 static bool IsStandardDirective(GraphQLDirective directive) => directive.Name == "skip" || directive.Name == "include" || directive.Name == "deprecated";
 public virtual GraphQLDirective EndVisitDirective(GraphQLDirective directive)
 {
     return(directive);
 }
        public string PrintAstDirective(GraphQLDirective directive)
        {
            var ast = _converter.Directive(directive);

            return(AstPrinter.Print(ast));
        }
        public override GraphQLDirective BeginVisitDirective(GraphQLDirective directive)
        {
            this.directive = directive;

            return(base.BeginVisitDirective(directive));
        }
Пример #25
0
        public string PrintAstDirective(GraphQLDirective directive)
        {
            Schema?.Initialize();

            return(directive.Print());
        }
Пример #26
0
        public override GraphQLDirective BeginVisitDirective(GraphQLDirective directive)
        {
            this.knownArgumentNames = new Dictionary <string, GraphQLName>();

            return(base.BeginVisitDirective(directive));
        }
        public string PrintAstDirective(GraphQLDirective directive)
        {
            Schema?.Initialize();

            return(AstPrinter.Print(CoreToVanillaConverter.Directive(directive)));
        }