Пример #1
0
        public void Validate(IDocumentValidatorContext context, DocumentNode document)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (document is null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            IDefinitionNode?typeSystemNode = null;

            for (var i = 0; i < document.Definitions.Count; i++)
            {
                IDefinitionNode node = document.Definitions[i];
                if (node.Kind is not SyntaxKind.OperationDefinition
                    and not SyntaxKind.FragmentDefinition)
                {
                    typeSystemNode = node;
                    break;
                }
            }

            if (typeSystemNode is not null)
            {
                context.Errors.Add(context.TypeSystemDefinitionNotAllowed(typeSystemNode));
            }
        }