diff --git a/.changeset/fix-query-serialization.md b/.changeset/fix-query-serialization.md new file mode 100644 index 0000000..ecf15bd --- /dev/null +++ b/.changeset/fix-query-serialization.md @@ -0,0 +1,5 @@ +--- +"@labdigital/graphql-fetcher": patch +--- + +Fix query serialization producing `[object Object]` instead of the actual query string diff --git a/src/client.ts b/src/client.ts index e4421c4..7f8357e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,6 +1,5 @@ import type { DocumentTypeDecoration } from "@graphql-typed-document-node/core"; import { type GraphQLError, print } from "graphql"; -import { isNode } from "graphql/language/ast.js"; import { createRequest, createRequestBody, @@ -130,9 +129,9 @@ export const initClientFetcher = } const query = - isNode(astNode) && astNode.kind === "Document" - ? print(astNode) - : astNode.toString(); + typeof astNode === "string" || astNode instanceof String + ? astNode.toString() + : print(astNode as Parameters[0]); const documentId = createDocumentId(astNode); const request = await createRequest( query, diff --git a/src/server.ts b/src/server.ts index 16ac03d..72eb43c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -11,7 +11,6 @@ import { hasPersistedQueryError, } from "./helpers"; import { print, type GraphQLError } from "graphql"; -import { isNode } from "graphql/language/ast.js"; import { createRequest, createRequestBody, @@ -118,9 +117,9 @@ export const initServerFetcher = options: RequestOptions = {}, ): Promise> => { const query = - isNode(astNode) && astNode.kind === "Document" - ? print(astNode) - : astNode.toString(); + typeof astNode === "string" || astNode instanceof String + ? astNode.toString() + : print(astNode as Parameters[0]); const documentId = createDocumentId(astNode); const request = await createRequest(