WooCommerce Code Reference

DocumentValidator
in package

Implements the "Validation" section of the spec.

Validation runs synchronously, returning an array of encountered errors, or an empty array if no errors were encountered and the document is valid.

A list of specific validation rules may be provided. If not provided, the default list of rules defined by the Automattic\WooCommerce\Vendor\GraphQL specification will be used.

Each validation rule is an instance of Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\ValidationRule which returns a visitor (see the Automattic\WooCommerce\Vendor\GraphQL\Language\Visitor API).

Visitor methods are expected to return an instance of Automattic\WooCommerce\Vendor\GraphQL\Error\Error, or array of such instances when invalid.

Optionally a custom TypeInfo instance may be provided. If not provided, one will be created from the provided schema.

Table of Contents

$defaultRules  : array<string|int, mixed>
$initRules  : bool
$rules  : array<string|int, mixed>
$sdlRules  : array<string|int, mixed>
$securityRules  : array<string|int, mixed>
addRule()  : void
Add rule to list of global validation rules.
allRules()  : array<string, ValidationRule>
Returns all global validation rules.
assertValidSDL()  : void
assertValidSDLExtension()  : void
defaultRules()  : array<class-string<\Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\ValidationRule>, ValidationRule>
getRule()  : ValidationRule|null
Returns global validation rule by name.
removeRule()  : void
Remove rule from list of global validation rules.
sdlRules()  : array<class-string<\Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\ValidationRule>, ValidationRule>
securityRules()  : array<class-string<\Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\QuerySecurityRule>, QuerySecurityRule>
validate()  : array<int, Error>
Validate a Automattic\WooCommerce\Vendor\GraphQL query against a schema.
validateSDL()  : array<int, Error>
Validate a Automattic\WooCommerce\Vendor\GraphQL document defined through schema definition language.
combineErrorMessages()  : string

Properties

Methods

getRule()

Returns global validation rule by name.

public static getRule(string $name) : ValidationRule|null

Standard rules are named by class name, so example usage for such rules:

Parameters
$name : string
Tags
example

DocumentValidator::getRule(Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\QueryComplexity::class);

throws
InvalidArgumentException
Return values
ValidationRule|null

securityRules()

public static securityRules() : array<class-string<\Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\QuerySecurityRule>, QuerySecurityRule>
Tags
deprecated

just add rules via @see DocumentValidator::addRule()

throws
InvalidArgumentException
Return values
array<class-string<\Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\QuerySecurityRule>, QuerySecurityRule>

validate()

Validate a Automattic\WooCommerce\Vendor\GraphQL query against a schema.

public static validate(Schema $schema, DocumentNode $ast[, array<string|int, ValidationRule>|null $rules = null ][, TypeInfo|null $typeInfo = null ]) : array<int, Error>
Parameters
$schema : Schema
$ast : DocumentNode
$rules : array<string|int, ValidationRule>|null = null

Defaults to using all available rules

$typeInfo : TypeInfo|null = null
Tags
throws
Exception
Return values
array<int, Error>

validateSDL()

Validate a Automattic\WooCommerce\Vendor\GraphQL document defined through schema definition language.

public static validateSDL(DocumentNode $documentAST[, Schema|null $schemaToExtend = null ][, array<string|int, ValidationRule>|null $rules = null ]) : array<int, Error>
Parameters
$documentAST : DocumentNode
$schemaToExtend : Schema|null = null
$rules : array<string|int, ValidationRule>|null = null
Tags
throws
Exception
Return values
array<int, Error>