Esempio n. 1
0
        protected override ISyntaxVisitorAction Enter(
            FieldNode node,
            IDocumentValidatorContext context)
        {
            SelectionSetNode selectionSet = context.SelectionSets.Peek();

            if (!context.FieldSets.TryGetValue(selectionSet, out IList <FieldInfo>?fields))
            {
                fields = context.RentFieldInfoList();
                context.FieldSets.Add(selectionSet, fields);
            }

            if (IntrospectionFields.TypeName.Equals(node.Name.Value))
            {
                fields.Add(new FieldInfo(context.Types.Peek(), context.NonNullString, node));
                return(Skip);
            }
            else if (context.Types.TryPeek(out IType type) &&
                     type.NamedType() is IComplexOutputType ct)
            {
                if (ct.Fields.TryGetField(node.Name.Value, out IOutputField of))
                {
                    fields.Add(new FieldInfo(context.Types.Peek(), of.Type, node));

                    if (node.SelectionSet is null)
                    {
                        if (of.Type.NamedType().IsCompositeType())
                        {
                            context.Errors.Add(context.NoSelectionOnCompositeField(
                                                   node, ct, of.Type));
                        }
                    }
                    else
                    {
                        if (of.Type.NamedType().IsLeafType())
                        {
                            context.Errors.Add(context.LeafFieldsCannotHaveSelections(
                                                   node, ct, of.Type));
                            return(Skip);
                        }
                    }

                    context.OutputFields.Push(of);
                    context.Types.Push(of.Type);
                    return(Continue);
                }
                else
                {
                    context.Errors.Add(context.FieldDoesNotExist(node, ct));
                    return(Skip);
                }
            }