Skip to content

Commit 4c8287b

Browse files
korsvanloonblurrah
authored andcommitted
JSON parse the output of print
1 parent 9a078cf commit 4c8287b

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {
1010
hasPersistedQueryError,
1111
mergeHeaders,
1212
} from "./helpers";
13-
import { print } from "graphql/language/printer";
14-
import { ASTNode } from "graphql";
13+
import { print, ASTNode } from "graphql";
1514

1615
type Options = {
1716
/**
@@ -70,7 +69,7 @@ export const initClientFetcher =
7069
if (!options.signal) {
7170
options.signal = AbortSignal.timeout(defaultTimeout);
7271
}
73-
const query = print(astNode as ASTNode);
72+
const query = JSON.parse(print(astNode as ASTNode));
7473
const operationName = extractOperationName(query);
7574

7675
let hash = "";

src/server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111
getQueryType,
1212
pruneObject,
1313
} from "./helpers";
14-
import { print } from "graphql/language/printer";
15-
import { ASTNode } from "graphql";
14+
import { print, ASTNode } from "graphql";
1615

1716
type Options = {
1817
/**
@@ -51,7 +50,7 @@ export const initServerFetcher =
5150
{ cache, next = {} }: CacheOptions,
5251
signal: AbortSignal = AbortSignal.timeout(defaultTimeout)
5352
): Promise<GqlResponse<TResponse>> => {
54-
const query = print(astNode as ASTNode);
53+
const query = JSON.parse(print(astNode as ASTNode));
5554
const operationName = extractOperationName(query) || "(GraphQL)";
5655

5756
if (dangerouslyDisableCache) {

src/testing.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ export class TypedDocumentString<TResult, TVariables>
99
constructor(private value: string, public __meta__?: Record<string, any>) {
1010
super(value);
1111
}
12+
13+
// Choosing a leaf type will trigger the print visitor to output the value directly
14+
// instead of trying to visit the children
15+
kind = "StringValue";
1216
}

0 commit comments

Comments
 (0)