mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 17:18:23 +00:00
Collect usage only when Apollo Server did resolve source (#3017)
This commit is contained in:
parent
dc683c2e68
commit
6023be2a0b
4 changed files with 48 additions and 1 deletions
5
.changeset/curvy-maps-deny.md
Normal file
5
.changeset/curvy-maps-deny.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@graphql-hive/client': patch
|
||||
---
|
||||
|
||||
Do not collect usage when Apollo Server did not resolve source
|
||||
|
|
@ -153,6 +153,7 @@ export function hiveApollo(clientOrOptions: HiveClient | HivePluginOptions): Apo
|
|||
const isLegacyV3 = 'context' in context;
|
||||
|
||||
let doc: DocumentNode;
|
||||
let didResolveSource = false;
|
||||
const complete = hive.collectUsage();
|
||||
const args = {
|
||||
schema: context.schema,
|
||||
|
|
@ -166,7 +167,18 @@ export function hiveApollo(clientOrOptions: HiveClient | HivePluginOptions): Apo
|
|||
|
||||
if (isLegacyV0) {
|
||||
return {
|
||||
didResolveSource() {
|
||||
didResolveSource = true;
|
||||
},
|
||||
willSendResponse(ctx: any) {
|
||||
if (!didResolveSource) {
|
||||
complete(args, {
|
||||
action: 'abort',
|
||||
reason: 'Did not resolve source',
|
||||
logging: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
doc = ctx.document;
|
||||
complete(args, ctx.response);
|
||||
},
|
||||
|
|
@ -175,12 +187,25 @@ export function hiveApollo(clientOrOptions: HiveClient | HivePluginOptions): Apo
|
|||
|
||||
if (isLegacyV3) {
|
||||
return Promise.resolve({
|
||||
didResolveSource() {
|
||||
didResolveSource = true;
|
||||
},
|
||||
async willSendResponse(ctx) {
|
||||
if (!didResolveSource) {
|
||||
complete(args, {
|
||||
action: 'abort',
|
||||
reason: 'Did not resolve source',
|
||||
logging: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ctx.document) {
|
||||
const details = ctx.operationName ? `operationName: ${ctx.operationName}` : '';
|
||||
complete(args, {
|
||||
action: 'abort',
|
||||
reason: 'Document is not available' + (details ? ` (${details})` : ''),
|
||||
logging: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
@ -193,12 +218,25 @@ export function hiveApollo(clientOrOptions: HiveClient | HivePluginOptions): Apo
|
|||
|
||||
// v4
|
||||
return Promise.resolve({
|
||||
didResolveSource() {
|
||||
didResolveSource = true;
|
||||
},
|
||||
async willSendResponse(ctx) {
|
||||
if (!didResolveSource) {
|
||||
complete(args, {
|
||||
action: 'abort',
|
||||
reason: 'Did not resolve source',
|
||||
logging: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ctx.document) {
|
||||
const details = ctx.operationName ? `operationName: ${ctx.operationName}` : '';
|
||||
complete(args, {
|
||||
action: 'abort',
|
||||
reason: 'Document is not available' + (details ? ` (${details})` : ''),
|
||||
logging: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
@ -208,6 +246,7 @@ export function hiveApollo(clientOrOptions: HiveClient | HivePluginOptions): Apo
|
|||
complete(args, {
|
||||
action: 'abort',
|
||||
reason: '@defer and @stream is not supported by Hive',
|
||||
logging: true,
|
||||
});
|
||||
} else {
|
||||
complete(args, ctx.response.body.singleResult);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export type AsyncIterableOrValue<T> = AsyncIterable<T> | T;
|
|||
export type AbortAction = {
|
||||
action: 'abort';
|
||||
reason: string;
|
||||
logging: boolean;
|
||||
};
|
||||
|
||||
export type CollectUsageCallback = (
|
||||
|
|
|
|||
|
|
@ -157,7 +157,9 @@ export function createUsage(pluginOptions: HivePluginOptions): UsageCollector {
|
|||
let providedOperationName: string | undefined = undefined;
|
||||
try {
|
||||
if (isAbortAction(result)) {
|
||||
logger.info(result.reason);
|
||||
if (result.logging) {
|
||||
logger.info(result.reason);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue