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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / lib / packages / GraphQL / GraphQL.php
woocommerce / lib / packages / GraphQL Last commit date
Error 2 months ago Executor 2 months ago Language 2 months ago Server 2 months ago Type 2 months ago Utils 2 months ago Validator 2 months ago Deferred.php 2 months ago GraphQL.php 2 months ago
GraphQL.php
266 lines
1 <?php declare(strict_types=1);
2
3 namespace Automattic\WooCommerce\Vendor\GraphQL;
4
5 use Automattic\WooCommerce\Vendor\GraphQL\Error\Error;
6 use Automattic\WooCommerce\Vendor\GraphQL\Error\InvariantViolation;
7 use Automattic\WooCommerce\Vendor\GraphQL\Executor\ExecutionResult;
8 use Automattic\WooCommerce\Vendor\GraphQL\Executor\Executor;
9 use Automattic\WooCommerce\Vendor\GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
10 use Automattic\WooCommerce\Vendor\GraphQL\Executor\Promise\Promise;
11 use Automattic\WooCommerce\Vendor\GraphQL\Executor\Promise\PromiseAdapter;
12 use Automattic\WooCommerce\Vendor\GraphQL\Language\AST\DocumentNode;
13 use Automattic\WooCommerce\Vendor\GraphQL\Language\Parser;
14 use Automattic\WooCommerce\Vendor\GraphQL\Language\Source;
15 use Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Directive;
16 use Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\ScalarType;
17 use Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\Type;
18 use Automattic\WooCommerce\Vendor\GraphQL\Type\Schema as SchemaType;
19 use Automattic\WooCommerce\Vendor\GraphQL\Validator\DocumentValidator;
20 use Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\QueryComplexity;
21 use Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules\ValidationRule;
22
23 /**
24 * This is the primary facade for fulfilling Automattic\WooCommerce\Vendor\GraphQL operations.
25 * See [related documentation](executing-queries.md).
26 *
27 * @phpstan-import-type ArgsMapper from Executor
28 * @phpstan-import-type FieldResolver from Executor
29 *
30 * @see \Automattic\WooCommerce\Vendor\GraphQL\Tests\GraphQLTest
31 */
32 class GraphQL
33 {
34 /**
35 * Executes graphql query.
36 *
37 * More sophisticated Automattic\WooCommerce\Vendor\GraphQL servers, such as those which persist queries,
38 * may wish to separate the validation and execution phases to a static time
39 * tooling step, and a server runtime step.
40 *
41 * Available options:
42 *
43 * schema:
44 * The Automattic\WooCommerce\Vendor\GraphQL type system to use when validating and executing a query.
45 * source:
46 * A Automattic\WooCommerce\Vendor\GraphQL language formatted string representing the requested operation.
47 * rootValue:
48 * The value provided as the first argument to resolver functions on the top
49 * level type (e.g. the query object type).
50 * contextValue:
51 * The context value is provided as an argument to resolver functions after
52 * field arguments. It is used to pass shared information useful at any point
53 * during executing this query, for example the currently logged in user and
54 * connections to databases or other services.
55 * If the passed object implements the `ScopedContext` interface,
56 * its `clone()` method will be called before passing the context down to a field.
57 * This allows passing information to child fields in the query tree without affecting sibling or parent fields.
58 * variableValues:
59 * A mapping of variable name to runtime value to use for all variables
60 * defined in the requestString.
61 * operationName:
62 * The name of the operation to use if requestString contains multiple
63 * possible operations. Can be omitted if requestString contains only
64 * one operation.
65 * fieldResolver:
66 * A resolver function to use when one is not provided by the schema.
67 * If not provided, the default field resolver is used (which looks for a
68 * value on the source value with the field's name).
69 * validationRules:
70 * A set of rules for query validation step. Default value is all available rules.
71 * Empty array would allow to skip query validation (may be convenient for persisted
72 * queries which are validated before persisting and assumed valid during execution)
73 *
74 * @param string|DocumentNode $source
75 * @param mixed $rootValue
76 * @param mixed $contextValue
77 * @param array<string, mixed>|null $variableValues
78 * @param array<ValidationRule>|null $validationRules
79 *
80 * @api
81 *
82 * @throws \Exception
83 * @throws InvariantViolation
84 */
85 public static function executeQuery(
86 SchemaType $schema,
87 $source,
88 $rootValue = null,
89 $contextValue = null,
90 ?array $variableValues = null,
91 ?string $operationName = null,
92 ?callable $fieldResolver = null,
93 ?array $validationRules = null
94 ): ExecutionResult {
95 $promiseAdapter = new SyncPromiseAdapter();
96
97 $promise = self::promiseToExecute(
98 $promiseAdapter,
99 $schema,
100 $source,
101 $rootValue,
102 $contextValue,
103 $variableValues,
104 $operationName,
105 $fieldResolver,
106 $validationRules
107 );
108
109 return $promiseAdapter->wait($promise);
110 }
111
112 /**
113 * Same as executeQuery(), but requires PromiseAdapter and always returns a Promise.
114 * Useful for Async PHP platforms.
115 *
116 * @param string|DocumentNode $source
117 * @param mixed $rootValue
118 * @param mixed $context
119 * @param array<string, mixed>|null $variableValues
120 * @param array<ValidationRule>|null $validationRules Defaults to using all available rules
121 *
122 * @api
123 *
124 * @throws \Exception
125 */
126 public static function promiseToExecute(
127 PromiseAdapter $promiseAdapter,
128 SchemaType $schema,
129 $source,
130 $rootValue = null,
131 $context = null,
132 ?array $variableValues = null,
133 ?string $operationName = null,
134 ?callable $fieldResolver = null,
135 ?array $validationRules = null
136 ): Promise {
137 try {
138 $documentNode = $source instanceof DocumentNode
139 ? $source
140 : Parser::parse(new Source($source, 'GraphQL'));
141
142 if ($validationRules === null) {
143 $queryComplexity = DocumentValidator::getRule(QueryComplexity::class);
144 assert($queryComplexity instanceof QueryComplexity, 'should not register a different rule for QueryComplexity');
145
146 $queryComplexity->setRawVariableValues($variableValues);
147 } else {
148 foreach ($validationRules as $rule) {
149 if ($rule instanceof QueryComplexity) {
150 $rule->setRawVariableValues($variableValues);
151 }
152 }
153 }
154
155 $validationErrors = DocumentValidator::validate($schema, $documentNode, $validationRules);
156
157 if ($validationErrors !== []) {
158 return $promiseAdapter->createFulfilled(
159 new ExecutionResult(null, $validationErrors)
160 );
161 }
162
163 return Executor::promiseToExecute(
164 $promiseAdapter,
165 $schema,
166 $documentNode,
167 $rootValue,
168 $context,
169 $variableValues,
170 $operationName,
171 $fieldResolver
172 );
173 } catch (Error $e) {
174 return $promiseAdapter->createFulfilled(
175 new ExecutionResult(null, [$e])
176 );
177 }
178 }
179
180 /**
181 * Returns directives defined in Automattic\WooCommerce\Vendor\GraphQL spec.
182 *
183 * @deprecated use {@see Directive::builtInDirectives()}
184 *
185 * @throws InvariantViolation
186 *
187 * @return array<string, Directive>
188 *
189 * @api
190 */
191 public static function getStandardDirectives(): array
192 {
193 return Directive::builtInDirectives();
194 }
195
196 /**
197 * Returns built-in scalar types defined in Automattic\WooCommerce\Vendor\GraphQL spec.
198 *
199 * @deprecated use {@see Type::builtInScalars()}
200 *
201 * @throws InvariantViolation
202 *
203 * @return array<string, ScalarType>
204 *
205 * @api
206 */
207 public static function getStandardTypes(): array
208 {
209 return Type::builtInScalars();
210 }
211
212 /**
213 * Replaces standard types with types from this list (matching by name).
214 *
215 * Standard types not listed here remain untouched.
216 *
217 * @deprecated prefer per-schema scalar overrides via {@see \Automattic\WooCommerce\Vendor\GraphQL\Type\SchemaConfig::$types} or {@see \Automattic\WooCommerce\Vendor\GraphQL\Type\SchemaConfig::$typeLoader}
218 *
219 * @param array<string, ScalarType> $types
220 *
221 * @api
222 *
223 * @throws InvariantViolation
224 */
225 public static function overrideStandardTypes(array $types): void
226 {
227 Type::overrideStandardTypes($types);
228 }
229
230 /**
231 * Returns standard validation rules implementing Automattic\WooCommerce\Vendor\GraphQL spec.
232 *
233 * @return array<class-string<ValidationRule>, ValidationRule>
234 *
235 * @api
236 */
237 public static function getStandardValidationRules(): array
238 {
239 return DocumentValidator::defaultRules();
240 }
241
242 /**
243 * Set default resolver implementation.
244 *
245 * @phpstan-param FieldResolver $fn
246 *
247 * @api
248 */
249 public static function setDefaultFieldResolver(callable $fn): void
250 {
251 Executor::setDefaultFieldResolver($fn);
252 }
253
254 /**
255 * Set default args mapper implementation.
256 *
257 * @phpstan-param ArgsMapper $fn
258 *
259 * @api
260 */
261 public static function setDefaultArgsMapper(callable $fn): void
262 {
263 Executor::setDefaultArgsMapper($fn);
264 }
265 }
266