Example #1
0
    private void ValidateArguments(ITypeCompletionContext context, Directive directive)
    {
        var arguments = directive.ToNode().Arguments.ToDictionary(t => t.Name.Value);

        foreach (ArgumentNode argument in arguments.Values)
        {
            if (directive.Type.Arguments.TryGetField(
                    argument.Name.Value,
                    out Argument? arg))
            {
                if (!arg.Type.IsInstanceOfType(argument.Value))
                {
                    context.ReportError(
                        DirectiveCollection_ArgumentValueTypeIsWrong(
                            directive.Type,
                            context.Type,
                            directive.ToNode(),
                            _source,
                            arg.Name));
                }
            }
            else
            {
                context.ReportError(
                    DirectiveCollection_ArgumentDoesNotExist(
                        directive.Type,
                        context.Type,
                        directive.ToNode(),
                        _source,
                        argument.Name.Value));
            }
        }

        foreach (Argument argument in directive.Type.Arguments
                 .Where(a => a.Type.IsNonNullType()))
        {
            if (!arguments.TryGetValue(argument.Name, out ArgumentNode? arg) ||
                arg.Value is NullValueNode)
            {
                context.ReportError(
                    DirectiveCollection_ArgumentNonNullViolation(
                        directive.Type,
                        context.Type,
                        directive.ToNode(),
                        _source,
                        argument.Name));
            }
        }
    }