Detect missing DocumentNode in Apollo Server (#2979)

This commit is contained in:
Kamil Kisiela 2023-09-29 12:35:41 +02:00 committed by GitHub
parent 951322cdef
commit fa18b0a36b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@graphql-hive/client': patch
---
Detect missing DocumentNode in Apollo Server

View file

@ -176,6 +176,15 @@ export function hiveApollo(clientOrOptions: HiveClient | HivePluginOptions): Apo
if (isLegacyV3) {
return Promise.resolve({
async willSendResponse(ctx) {
if (!ctx.document) {
const details = ctx.operationName ? `operationName: ${ctx.operationName}` : '';
complete(args, {
action: 'abort',
reason: 'Document is not available' + (details ? ` (${details})` : ''),
});
return;
}
doc = ctx.document!;
complete(args, ctx.response as any);
},
@ -185,7 +194,16 @@ export function hiveApollo(clientOrOptions: HiveClient | HivePluginOptions): Apo
// v4
return Promise.resolve({
async willSendResponse(ctx) {
doc = ctx.document!;
if (!ctx.document) {
const details = ctx.operationName ? `operationName: ${ctx.operationName}` : '';
complete(args, {
action: 'abort',
reason: 'Document is not available' + (details ? ` (${details})` : ''),
});
return;
}
doc = ctx.document;
if (ctx.response.body.kind === 'incremental') {
complete(args, {
action: 'abort',