1717class GraphQL
1818{
1919 /**
20+ * This is the primary entry point function for fulfilling GraphQL operations
21+ * by parsing, validating, and executing a GraphQL document along side a
22+ * GraphQL schema.
23+ *
24+ * More sophisticated GraphQL servers, such as those which persist queries,
25+ * may wish to separate the validation and execution phases to a static time
26+ * tooling step, and a server runtime step.
27+ *
28+ * schema:
29+ * The GraphQL type system to use when validating and executing a query.
30+ * requestString:
31+ * A GraphQL language formatted string representing the requested operation.
32+ * rootValue:
33+ * The value provided as the first argument to resolver functions on the top
34+ * level type (e.g. the query object type).
35+ * variableValues:
36+ * A mapping of variable name to runtime value to use for all variables
37+ * defined in the requestString.
38+ * operationName:
39+ * The name of the operation to use if requestString contains multiple
40+ * possible operations. Can be omitted if requestString contains only
41+ * one operation.
42+ * fieldResolver:
43+ * A resolver function to use when one is not provided by the schema.
44+ * If not provided, the default field resolver is used (which looks for a
45+ * value or method on the source value with the field's name).
46+ *
2047 * @param Schema $schema
2148 * @param string|DocumentNode $requestString
2249 * @param mixed $rootValue
2350 * @param array|null $variableValues
2451 * @param string|null $operationName
52+ * @param callable $fieldResolver
2553 * @return Promise|array
2654 */
27- public static function execute (Schema $ schema , $ requestString , $ rootValue = null , $ contextValue = null , $ variableValues = null , $ operationName = null )
55+ public static function execute (
56+ Schema $ schema ,
57+ $ requestString ,
58+ $ rootValue = null ,
59+ $ contextValue = null ,
60+ $ variableValues = null ,
61+ $ operationName = null ,
62+ $ fieldResolver = null
63+ )
2864 {
29- $ result = self ::executeAndReturnResult ($ schema , $ requestString , $ rootValue , $ contextValue , $ variableValues , $ operationName );
65+ $ result = self ::executeAndReturnResult (
66+ $ schema ,
67+ $ requestString ,
68+ $ rootValue ,
69+ $ contextValue ,
70+ $ variableValues ,
71+ $ operationName ,
72+ $ fieldResolver
73+ );
3074
3175 if ($ result instanceof ExecutionResult) {
3276 return $ result ->toArray ();
@@ -40,14 +84,26 @@ public static function execute(Schema $schema, $requestString, $rootValue = null
4084 }
4185
4286 /**
87+ * Same as `execute`, but returns instance of ExecutionResult instead of array,
88+ * which can be used for custom error formatting or adding extensions to response
89+ *
4390 * @param Schema $schema
4491 * @param string|DocumentNode $requestString
4592 * @param mixed $rootValue
4693 * @param array|null $variableValues
4794 * @param string|null $operationName
95+ * @param callable $fieldResolver
4896 * @return ExecutionResult|Promise
4997 */
50- public static function executeAndReturnResult (Schema $ schema , $ requestString , $ rootValue = null , $ contextValue = null , $ variableValues = null , $ operationName = null )
98+ public static function executeAndReturnResult (
99+ Schema $ schema ,
100+ $ requestString ,
101+ $ rootValue = null ,
102+ $ contextValue = null ,
103+ $ variableValues = null ,
104+ $ operationName = null ,
105+ $ fieldResolver = null
106+ )
51107 {
52108 try {
53109 if ($ requestString instanceof DocumentNode) {
@@ -66,7 +122,15 @@ public static function executeAndReturnResult(Schema $schema, $requestString, $r
66122 if (!empty ($ validationErrors )) {
67123 return new ExecutionResult (null , $ validationErrors );
68124 } else {
69- return Executor::execute ($ schema , $ documentNode , $ rootValue , $ contextValue , $ variableValues , $ operationName );
125+ return Executor::execute (
126+ $ schema ,
127+ $ documentNode ,
128+ $ rootValue ,
129+ $ contextValue ,
130+ $ variableValues ,
131+ $ operationName ,
132+ $ fieldResolver
133+ );
70134 }
71135 } catch (Error $ e ) {
72136 return new ExecutionResult (null , [$ e ]);
0 commit comments