Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphcache): Use stringifyDocument in offlineExchange and support extensions #3094

Merged
merged 4 commits into from
Mar 24, 2023
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/giant-flies-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/exchange-graphcache': patch
---

Use `stringifyDocument` in `offlineExchange` rather than `print` and serialize `operation.extensions` as needed.
9 changes: 6 additions & 3 deletions exchanges/graphcache/src/offlineExchange.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { pipe, merge, makeSubject, filter } from 'wonka';
import { print, SelectionNode } from 'graphql';
import { SelectionNode } from 'graphql';

import {
Operation,
OperationResult,
Exchange,
ExchangeIO,
CombinedError,
stringifyDocument,
createRequest,
makeOperation,
} from '@urql/core';
Expand Down Expand Up @@ -134,8 +135,9 @@ export const offlineExchange =
const operation = failedQueue[i];
if (operation.kind === 'mutation') {
requests.push({
query: print(operation.query),
query: stringifyDocument(operation.query),
variables: operation.variables,
extensions: operation.extensions,
});
}
}
Expand Down Expand Up @@ -190,7 +192,8 @@ export const offlineExchange =
failedQueue.push(
client.createRequestOperation(
'mutation',
createRequest(mutations[i].query, mutations[i].variables)
createRequest(mutations[i].query, mutations[i].variables),
mutations[i].extensions
)
);
}
Expand Down
5 changes: 3 additions & 2 deletions exchanges/graphcache/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyVariables, TypedDocumentNode } from '@urql/core';
import { AnyVariables, TypedDocumentNode, RequestExtensions } from '@urql/core';
import { GraphQLError, DocumentNode, FragmentDefinitionNode } from 'graphql';
import { IntrospectionData } from './ast';

Expand Down Expand Up @@ -888,7 +888,8 @@ export interface SerializedEntries {
/** A serialized GraphQL request for offline storage. */
export interface SerializedRequest {
query: string;
variables: AnyVariables;
variables: AnyVariables | undefined;
extensions?: RequestExtensions | undefined;
}

/** Interface for a storage adapter, used by the {@link offlineExchange} for Offline Support.
Expand Down