From 062d4bacf8b39dbc3ac992d93f6893a270f56f65 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Fri, 20 Sep 2024 13:16:01 +0100 Subject: [PATCH] fix: Add missing setter to `loc` property (#400) --- .changeset/forty-paws-yawn.md | 5 +++++ src/api.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/forty-paws-yawn.md diff --git a/.changeset/forty-paws-yawn.md b/.changeset/forty-paws-yawn.md new file mode 100644 index 00000000..e8cc4023 --- /dev/null +++ b/.changeset/forty-paws-yawn.md @@ -0,0 +1,5 @@ +--- +'gql.tada': patch +--- + +Add missing setter to `loc` property diff --git a/src/api.ts b/src/api.ts index a159b2fe..67e75883 100644 --- a/src/api.ts +++ b/src/api.ts @@ -339,6 +339,7 @@ export function initGraphQLTada(): init ); } + let loc: Location | undefined; return { kind: Kind.DOCUMENT, definitions, @@ -346,7 +347,7 @@ export function initGraphQLTada(): init // NOTE: This is only meant for graphql-tag compatibility. When fragment documents // are interpolated into other documents, graphql-tag blindly reads `document.loc` // without checking whether it's `undefined`. - if (isFragment) { + if (!loc && isFragment) { const body = input + concatLocSources(fragments || []); return { start: 0, @@ -358,6 +359,10 @@ export function initGraphQLTada(): init }, }; } + return loc; + }, + set loc(_loc: Location) { + loc = _loc; }, } satisfies DocumentNode; }