Skip to content

Commit 8f36279

Browse files
committed
Fix v4.2.0 regression in variables: null (et al)
In v4.2.0 (#7171) we changed POST handling to be stricter if `operationName`, `variables`, or `extensions` were provided with a surprising data type. This was intended to pass more of the optional recommendations of the GraphQL Over HTTP spec as tested by the graphql-http audit suite. However, we were overzealous and also banned providing these parameters as an explicit `null`, which is documented by the spec as legitimate. (And some clients, such as FIXME, actually send `variables: null` in practice.) We added explicit tests for this to the `graphql-http` test suite (graphql/graphql-http#28) and this commit allows these `null`s again. Fixes #7200.
1 parent 4d34cfa commit 8f36279

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

.changeset/red-cats-clap.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@apollo/server-integration-testsuite': patch
3+
'@apollo/server': patch
4+
---
5+
6+
Fix v4.2.0 (#7171) regression where `"operationName": null`, `"variables": null`, and `"extensions": null` in POST bodies were improperly rejected.

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/integration-testsuite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@josephg/resolvable": "^1.0.1",
3737
"body-parser": "^1.20.0",
3838
"express": "^4.18.1",
39-
"graphql-http": "1.8.0",
39+
"graphql-http": "1.9.0",
4040
"graphql-tag": "^2.12.6",
4141
"loglevel": "^1.8.0",
4242
"node-fetch": "^2.6.7",

packages/server/src/runHttpQuery.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export async function runHttpQuery<TContext extends BaseContext>({
155155

156156
if (
157157
'extensions' in httpRequest.body &&
158+
httpRequest.body.extensions !== null &&
158159
!isStringRecord(httpRequest.body.extensions)
159160
) {
160161
throw new BadRequestError(
@@ -164,6 +165,7 @@ export async function runHttpQuery<TContext extends BaseContext>({
164165

165166
if (
166167
'variables' in httpRequest.body &&
168+
httpRequest.body.variables !== null &&
167169
!isStringRecord(httpRequest.body.variables)
168170
) {
169171
throw new BadRequestError(
@@ -173,6 +175,7 @@ export async function runHttpQuery<TContext extends BaseContext>({
173175

174176
if (
175177
'operationName' in httpRequest.body &&
178+
httpRequest.body.operationName !== null &&
176179
typeof httpRequest.body.operationName !== 'string'
177180
) {
178181
throw new BadRequestError(

0 commit comments

Comments
 (0)