Skip to content

Commit

Permalink
Detect missing DocumentNode in Apollo Server (#2979)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Sep 29, 2023
1 parent 951322c commit fa18b0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fair-beds-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/client': patch
---

Detect missing DocumentNode in Apollo Server
20 changes: 19 additions & 1 deletion packages/libraries/client/src/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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',
Expand Down

0 comments on commit fa18b0a

Please sign in to comment.