diff --git a/.changeset/calm-buckets-perform.md b/.changeset/calm-buckets-perform.md new file mode 100644 index 000000000..f9d1a8a96 --- /dev/null +++ b/.changeset/calm-buckets-perform.md @@ -0,0 +1,5 @@ +--- +'@faustwp/core': patch +--- + +Fixed an issue where persisted queries were not being enabled properly when setting the `usePersistedQueries` flag. diff --git a/packages/faustwp-core/src/client.ts b/packages/faustwp-core/src/client.ts index c73400e36..c334adf1b 100644 --- a/packages/faustwp-core/src/client.ts +++ b/packages/faustwp-core/src/client.ts @@ -58,7 +58,12 @@ export function createApolloClient(authenticated = false) { let linkChain = createHttpLink({ uri: getGraphqlEndpoint(), - useGETForQueries, + /** + * Only add this option if usePersistedQueries is not set/false. + * When persisted queries is enabled and this flag and useGETForHashedQueries + * are both set, there is a conflict and persisted queries does not work. + */ + useGETForQueries: useGETForQueries && !usePersistedQueries, }); // If the user requested to use persisted queries, apply the link. diff --git a/packages/faustwp-core/tests/client.test.ts b/packages/faustwp-core/tests/client.test.ts index 81fd76f24..9a16c40ff 100644 --- a/packages/faustwp-core/tests/client.test.ts +++ b/packages/faustwp-core/tests/client.test.ts @@ -81,6 +81,25 @@ describe('createApolloClient', () => { expect(persistedQueriesLinkSpy).toHaveBeenCalledTimes(1); }); + it('Does not set useGETForQueries in HttpLink if persisted queries is enabled', () => { + process.env.NEXT_PUBLIC_WORDPRESS_URL = 'http://headless.local'; + + setConfig({ + usePersistedQueries: true, + } as any as FaustConfig); + + client.createApolloClient(); + + expect(httpLinkSpy).toHaveBeenCalledTimes(1); + + expect(httpLinkSpy).toHaveBeenCalledWith({ + uri: 'http://headless.local/index.php?graphql', + useGETForQueries: false, + }); + + expect(persistedQueriesLinkSpy).toHaveBeenCalledTimes(1); + }); + it('invokes setContext to set the proper auth headers if its an auth client', () => { client.createApolloClient(true);