22
33namespace Digia \GraphQL ;
44
5- use Digia \GraphQL \Error \ErrorProvider ;
5+ use Digia \GraphQL \Error \ErrorHandler ;
6+ use Digia \GraphQL \Error \ErrorHandlerInterface ;
67use Digia \GraphQL \Execution \ExecutionInterface ;
78use Digia \GraphQL \Execution \ExecutionProvider ;
89use Digia \GraphQL \Execution \ExecutionResult ;
@@ -61,7 +62,6 @@ class GraphQL
6162 * @var array
6263 */
6364 private static $ providers = [
64- ErrorProvider::class,
6565 LanguageProvider::class,
6666 SchemaBuildingProvider::class,
6767 SchemaExtensionProvider::class,
@@ -128,14 +128,16 @@ public static function make(string $id)
128128 */
129129 public static function buildSchema (Source $ source , $ resolverRegistry , array $ options = []): Schema
130130 {
131- return static ::make (SchemaBuilderInterface::class)
132- ->build (
133- static ::parse ($ source , $ options ),
134- $ resolverRegistry instanceof ResolverRegistryInterface
135- ? $ resolverRegistry
136- : new ResolverRegistry ($ resolverRegistry ),
137- $ options
138- );
131+ /** @var SchemaBuilderInterface $schemaBuilder */
132+ $ schemaBuilder = static ::make (SchemaBuilderInterface::class);
133+
134+ return $ schemaBuilder ->build (
135+ static ::parse ($ source , $ options ),
136+ $ resolverRegistry instanceof ResolverRegistryInterface
137+ ? $ resolverRegistry
138+ : new ResolverRegistry ($ resolverRegistry ),
139+ $ options
140+ );
139141 }
140142
141143 /**
@@ -151,15 +153,17 @@ public static function extendSchema(
151153 $ resolverRegistry ,
152154 array $ options = []
153155 ): Schema {
154- return static ::make (SchemaExtenderInterface::class)
155- ->extend (
156- $ schema ,
157- static ::parse ($ source , $ options ),
158- $ resolverRegistry instanceof ResolverRegistryInterface
159- ? $ resolverRegistry
160- : new ResolverRegistry ($ resolverRegistry ),
161- $ options
162- );
156+ /** @var SchemaExtenderInterface $schemaExtender */
157+ $ schemaExtender = static ::make (SchemaExtenderInterface::class);
158+
159+ return $ schemaExtender ->extend (
160+ $ schema ,
161+ static ::parse ($ source , $ options ),
162+ $ resolverRegistry instanceof ResolverRegistryInterface
163+ ? $ resolverRegistry
164+ : new ResolverRegistry ($ resolverRegistry ),
165+ $ options
166+ );
163167 }
164168
165169 /**
@@ -227,13 +231,14 @@ public static function validate(Schema $schema, DocumentNode $document): array
227231 }
228232
229233 /**
230- * @param Schema $schema
231- * @param DocumentNode $document
232- * @param mixed $rootValue
233- * @param mixed $contextValue
234- * @param array $variableValues
235- * @param string|null $operationName
236- * @param callable|null $fieldResolver
234+ * @param Schema $schema
235+ * @param DocumentNode $document
236+ * @param mixed $rootValue
237+ * @param mixed $contextValue
238+ * @param array $variableValues
239+ * @param string|null $operationName
240+ * @param callable|null $fieldResolver
241+ * @param ErrorHandlerInterface|callable|null $errorHandler
237242 * @return ExecutionResult
238243 */
239244 public static function execute (
@@ -243,19 +248,27 @@ public static function execute(
243248 $ contextValue = null ,
244249 array $ variableValues = [],
245250 $ operationName = null ,
246- callable $ fieldResolver = null
251+ callable $ fieldResolver = null ,
252+ $ errorHandler = null
247253 ): ExecutionResult {
248254 /** @var ExecutionInterface $execution */
249255 $ execution = static ::make (ExecutionInterface::class);
250256
257+ if (null !== $ errorHandler ) {
258+ $ errorHandler = $ errorHandler instanceof ErrorHandlerInterface
259+ ? $ errorHandler
260+ : new ErrorHandler ($ errorHandler );
261+ }
262+
251263 return $ execution ->execute (
252264 $ schema ,
253265 $ document ,
254266 $ rootValue ,
255267 $ contextValue ,
256268 $ variableValues ,
257269 $ operationName ,
258- $ fieldResolver
270+ $ fieldResolver ,
271+ $ errorHandler
259272 );
260273 }
261274
0 commit comments