Skip to content

Commit 418b76c

Browse files
committed
Rename HTTPGraphQLHead.statusCode to status
This matches the name in the Fetch Response API, so that `requestContext.response.http.status` does not have to change between AS3 and AS4. I think the previous rename was inspired by the Node HTTP response object's field name, but there are enough adjustments for AS4; let's avoid this little one.
1 parent a39273a commit 418b76c

File tree

13 files changed

+37
-30
lines changed

13 files changed

+37
-30
lines changed

.changeset/famous-parents-argue.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@apollo/server-integration-testsuite": patch
3+
"@apollo/server-plugin-response-cache": patch
4+
"@apollo/server": patch
5+
---
6+
7+
Rename response.http.statusCode back to status like it was in AS3.

docs/source/integrations/building-integrations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ In the above code snippet, the `httpGraphQLRequest` variable is our `HTTPGraphQL
205205
#### Handle errors
206206

207207
The `executeHTTPGraphQLRequest` method does not throw. Instead, it returns an
208-
object containing helpful errors and a specific `statusCode` when applicable.
208+
object containing helpful errors and a specific `status` when applicable.
209209
You should handle this object accordingly, based on the error handling
210210
conventions that apply to your framework.
211211

@@ -219,7 +219,7 @@ After awaiting the Promise returned by `executeHTTPGraphQLRequest`, we receive a
219219

220220
```ts
221221
interface HTTPGraphQLHead {
222-
statusCode?: number;
222+
status?: number;
223223
headers: Map<string, string>;
224224
}
225225

@@ -243,6 +243,6 @@ with the appropriate status code and headers, and finally sends the body:
243243
for (const [key, value] of httpGraphQLResponse.headers) {
244244
res.setHeader(key, value);
245245
}
246-
res.statusCode = httpGraphQLResponse.statusCode || 200;
246+
res.statusCode = httpGraphQLResponse.status || 200;
247247
res.send(httpGraphQLResponse.completeBody);
248248
```

packages/integration-testsuite/src/apolloServerTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ export function defineIntegrationTestSuiteApolloServerTests(
646646
},
647647
}) {
648648
if (errors![0].message === 'known_error') {
649-
http!.statusCode = 403;
649+
http!.status = 403;
650650
}
651651
},
652652
};

packages/integration-testsuite/src/httpServerTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ export function defineIntegrationTestSuiteHttpServerTests(
16691669
async requestDidStart() {
16701670
return {
16711671
async willSendResponse({ response: { http } }) {
1672-
http!.statusCode = 403;
1672+
http!.status = 403;
16731673
},
16741674
};
16751675
},

packages/plugin-response-cache/src/ApolloServerPluginResponseCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export default function plugin<TContext extends BaseContext>(
219219
return {
220220
result: { data: value.data },
221221
http: {
222-
statusCode: undefined,
222+
status: undefined,
223223
headers: new Map(),
224224
},
225225
};

packages/server/src/ApolloServer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -988,13 +988,13 @@ export class ApolloServer<in out TContext extends BaseContext = BaseContext> {
988988
error.message = `Context creation failed: ${error.message}`;
989989
// If we explicitly provide an error code that isn't
990990
// INTERNAL_SERVER_ERROR, we'll treat it as a client error.
991-
const statusCode =
991+
const status =
992992
error instanceof GraphQLError &&
993993
error.extensions.code &&
994994
error.extensions.code !== ApolloServerErrorCode.INTERNAL_SERVER_ERROR
995995
? 400
996996
: 500;
997-
return this.errorResponse(error, newHTTPGraphQLHead(statusCode));
997+
return this.errorResponse(error, newHTTPGraphQLHead(status));
998998
}
999999

10001000
return await runPotentiallyBatchedHttpQuery(
@@ -1027,7 +1027,7 @@ export class ApolloServer<in out TContext extends BaseContext = BaseContext> {
10271027
// subclasses, maybe?
10281028
maybeError.message === badMethodErrorMessage
10291029
? {
1030-
statusCode: 405,
1030+
status: 405,
10311031
headers: new HeaderMap([['allow', 'GET, POST']]),
10321032
}
10331033
: newHTTPGraphQLHead(400),
@@ -1042,7 +1042,7 @@ export class ApolloServer<in out TContext extends BaseContext = BaseContext> {
10421042
httpGraphQLHead: HTTPGraphQLHead = newHTTPGraphQLHead(),
10431043
): HTTPGraphQLResponse {
10441044
return {
1045-
statusCode: httpGraphQLHead.statusCode ?? 500,
1045+
status: httpGraphQLHead.status ?? 500,
10461046
headers: new HeaderMap([
10471047
...httpGraphQLHead.headers,
10481048
['content-type', 'application/json'],

packages/server/src/__tests__/ApolloServer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('ApolloServer start', () => {
211211
"headers": Map {
212212
"content-type" => "application/json",
213213
},
214-
"statusCode": 500,
214+
"status": 500,
215215
}
216216
`);
217217

@@ -224,7 +224,7 @@ describe('ApolloServer start', () => {
224224
"headers": Map {
225225
"content-type" => "application/json",
226226
},
227-
"statusCode": 500,
227+
"status": 500,
228228
}
229229
`);
230230

packages/server/src/express4/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function expressMiddleware<TContext extends BaseContext>(
9393
for (const [key, value] of httpGraphQLResponse.headers) {
9494
res.setHeader(key, value);
9595
}
96-
res.statusCode = httpGraphQLResponse.statusCode || 200;
96+
res.statusCode = httpGraphQLResponse.status || 200;
9797
res.send(httpGraphQLResponse.completeBody);
9898
})
9999
.catch(next);

packages/server/src/externalTypes/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface HTTPGraphQLResponseChunk {
2828
}
2929

3030
export interface HTTPGraphQLHead {
31-
statusCode?: number;
31+
status?: number;
3232
// TODO(AS4): need to figure out what headers this includes (eg JSON???)
3333
headers: Map<string, string>;
3434
}

packages/server/src/httpBatching.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export async function runBatchHttpQuery<TContext extends BaseContext>(
5151
combinedResponse.headers.set(key, value);
5252
}
5353
// If two responses both want to set the status code, one of them will win.
54-
// Note that the normal success case leaves statusCode empty.
55-
if (response.statusCode) {
56-
combinedResponse.statusCode = response.statusCode;
54+
// Note that the normal success case leaves status empty.
55+
if (response.status) {
56+
combinedResponse.status = response.status;
5757
}
5858
return response.completeBody;
5959
}),

0 commit comments

Comments
 (0)