Skip to content

Commit

Permalink
check for astnode
Browse files Browse the repository at this point in the history
  • Loading branch information
korsvanloon committed Oct 23, 2024
1 parent ef65256 commit ff88191
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
hasPersistedQueryError,
mergeHeaders,
} from "./helpers";
import { print, ASTNode } from "graphql";
import { print } from "graphql";
import { isNode } from "graphql/language/ast";

type Options = {
/**
Expand Down Expand Up @@ -69,7 +70,11 @@ export const initClientFetcher =
if (!options.signal) {
options.signal = AbortSignal.timeout(defaultTimeout);
}
const query = JSON.parse(print(astNode as ASTNode));

const query = isNode(astNode)
? JSON.parse(print(astNode))
: astNode.toString();

const operationName = extractOperationName(query);

let hash = "";
Expand Down
6 changes: 5 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
pruneObject,
} from "./helpers";
import { print, ASTNode } from "graphql";
import { isNode } from "graphql/language/ast";

type Options = {
/**
Expand Down Expand Up @@ -50,7 +51,10 @@ export const initServerFetcher =
{ cache, next = {} }: CacheOptions,
signal: AbortSignal = AbortSignal.timeout(defaultTimeout)
): Promise<GqlResponse<TResponse>> => {
const query = JSON.parse(print(astNode as ASTNode));
const query = isNode(astNode)
? JSON.parse(print(astNode))
: astNode.toString();

const operationName = extractOperationName(query) || "(GraphQL)";

if (dangerouslyDisableCache) {
Expand Down

0 comments on commit ff88191

Please sign in to comment.