Пример #1
0
        protected override ISyntaxVisitorAction Enter(
            ObjectValueNode node,
            IDocumentValidatorContext context)
        {
            context.Names.Clear();

            for (var i = 0; i < node.Fields.Count; i++)
            {
                ObjectFieldNode field = node.Fields[i];
                if (!context.Names.Add(field.Name.Value))
                {
                    context.Errors.Add(context.InputFieldAmbiguous(field));
                }
            }

            INamedType namedType = context.Types.Peek().NamedType();

            if (namedType.IsLeafType())
            {
                return(Enter((IValueNode)node, context));
            }

            if (namedType is InputObjectType inputObjectType)
            {
                if (context.Names.Count >= inputObjectType.Fields.Count)
                {
                    return(Continue);
                }

                for (var i = 0; i < inputObjectType.Fields.Count; i++)
                {
                    IInputField field = inputObjectType.Fields[i];
                    if (field.Type.IsNonNullType() &&
                        field.DefaultValue.IsNull() &&
                        context.Names.Add(field.Name))
                    {
                        context.Errors.Add(
                            context.FieldIsRequiredButNull(node, field.Name));
                    }
                }
            }
            else
            {
                context.UnexpectedErrorsDetected = true;
            }

            return(Continue);
        }