From 3c66b7985730aaa1e88f95e42114ab226a1e8682 Mon Sep 17 00:00:00 2001 From: Aarne Laur Date: Fri, 29 Dec 2023 10:48:17 +0100 Subject: [PATCH] fix: Trigger NoLiveMixedWithDeferStreamRule only if query has @live directive Some queries with fragments marked with @defer would trigger this error without actually having @live directive in the query --- .../src/rules/NoLiveMixedWithDeferStreamRule.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/graphql-live-query/src/rules/NoLiveMixedWithDeferStreamRule.ts b/packages/graphql-live-query/src/rules/NoLiveMixedWithDeferStreamRule.ts index 8ab5c8ea..8c0c19de 100644 --- a/packages/graphql-live-query/src/rules/NoLiveMixedWithDeferStreamRule.ts +++ b/packages/graphql-live-query/src/rules/NoLiveMixedWithDeferStreamRule.ts @@ -4,16 +4,21 @@ import { getLiveDirectiveNode } from "../getLiveDirectiveNode.js"; import { isNone } from "../Maybe.js"; export const NoLiveMixedWithDeferStreamRule: ValidationRule = (context) => { + let opmatch = false; return { OperationDefinition(operationDefinitionNode) { if (isNone(getLiveDirectiveNode(operationDefinitionNode))) { return false; + } else { + opmatch = true; } }, Directive(directiveNode) { if ( - directiveNode.name.value === "defer" || - directiveNode.name.value === "stream" + opmatch && ( + directiveNode.name.value === "defer" || + directiveNode.name.value === "stream" + ) ) { context.reportError( new GraphQLError(