Example #1
0
        public override object VisitArguments(GraphQLParser.ArgumentsContext context)
        {
            var arguments = new Arguments();

            foreach (var arg in context.argument())
            {
                arguments.Add((Argument)Visit(arg));
            }

            return(arguments);
        }
Example #2
0
        void ValidateArguments(__Field field, GraphQLParser.ArgumentsContext arguments)
        {
            if (arguments.argument().Select(x => x.NAME().GetText()).Distinct().Count() != arguments.argument().Count())
            {
                Error($"argument names are not unique", arguments);
            }

            foreach (var c in arguments.argument().Select(x => new { text = x.NAME().GetText(), ctx = x }))
            {
                var inputValue = field.GetInputValue(c.text);
                if (inputValue == null)
                {
                    Error($"Received a named argument - {c.text} that is not expected for field {field.name}", c.ctx);
                }

                var valueOrVariable = c.ctx.valueOrVariable();

                if (valueOrVariable.value() != null)
                {
                    ValidateArgumentType(valueOrVariable.value(), inputValue.type);
                }
            }

            foreach (var q in field.args)
            {
                if (q.type.kind == __TypeKind.NON_NULL)
                {
                    var argument = arguments.argument().FirstOrDefault(x => x.NAME().GetText() != q.name);
                    if (argument == null)
                    {
                        Error($"A required field - {q.name} is missing", arguments);
                        return;
                    }

                    if (argument.valueOrVariable().value().ToString() == "null")
                    {
                        Error($"A non-null field - {q.name} is called with null argument", arguments);
                    }
                }
            }
        }
Example #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="GraphQLParser.arguments"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitArguments([NotNull] GraphQLParser.ArgumentsContext context)
 {
 }