Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-query-serialization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/graphql-fetcher": patch
---

Fix query serialization producing `[object Object]` instead of the actual query string
7 changes: 3 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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<typeof print>[0]);
const documentId = createDocumentId(astNode);
const request = await createRequest(
query,
Expand Down
7 changes: 3 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
hasPersistedQueryError,
} from "./helpers";
import { print, type GraphQLError } from "graphql";
import { isNode } from "graphql/language/ast.js";
import {
createRequest,
createRequestBody,
Expand Down Expand Up @@ -118,9 +117,9 @@ export const initServerFetcher =
options: RequestOptions = {},
): Promise<GqlResponse<TResponse>> => {
const query =
isNode(astNode) && astNode.kind === "Document"
? print(astNode)
: astNode.toString();
typeof astNode === "string" || astNode instanceof String
? astNode.toString()
: print(astNode as Parameters<typeof print>[0]);

const documentId = createDocumentId(astNode);
const request = await createRequest(
Expand Down
Loading