@@ -65,6 +65,7 @@ public function listen()
65
65
{
66
66
// obtain query and variables
67
67
$ variables = $ this ->getVariables ();
68
+ $ operationName = $ this ->getOperationName ();
68
69
$ query = $ this ->getQuery ();
69
70
70
71
if ($ query === null ) {
@@ -103,7 +104,7 @@ public function listen()
103
104
104
105
105
106
// execute query
106
- $ result = $ this ->executor ->execute ($ this ->schema , $ this ->parser ->getParsedDocument (), null , null , $ variables );
107
+ $ result = $ this ->executor ->execute ($ this ->schema , $ this ->parser ->getParsedDocument (), null , null , $ variables, $ operationName );
107
108
$ this ->returnData ($ result );
108
109
109
110
} catch (Error $ error ) {
@@ -151,6 +152,25 @@ private function getQuery(): ?string
151
152
}
152
153
}
153
154
155
+ /**
156
+ * Returns the operation name string from the raw post data.
157
+ *
158
+ * @return string|null
159
+ */
160
+ private function getOperationName (): ?string
161
+ {
162
+ // check if query is sent as raw http body in request as "application/json" or via post fields as "multipart/form-data"
163
+ $ headers = apache_request_headers ();
164
+ if (array_key_exists ("Content-Type " , $ headers ) and $ headers ["Content-Type " ] === "application/json " ) {
165
+ // raw json string in http body
166
+ $ phpInput = json_decode (file_get_contents ("php://input " ), true );
167
+ return $ phpInput ["operationName " ] ?? null ;
168
+ } else {
169
+ // query sent via post field
170
+ return $ _POST ["operationName " ] ?? null ;
171
+ }
172
+ }
173
+
154
174
/**
155
175
* Returns the variables, sent by raw post data.
156
176
*
0 commit comments