Skip to content

Commit

Permalink
Disable createHttpLink useGETForQueries option if persisted queri…
Browse files Browse the repository at this point in the history
…es is enabled (#1548)

* Disable `createHttpLink` `useGETForQueries` option if persisted queries is enabled

* Testing commit

* Revert "Testing commit"

This reverts commit 2e1f9d4.

* Add changeset
  • Loading branch information
blakewilson authored Aug 24, 2023
1 parent 23f64e6 commit a419252
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/calm-buckets-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@faustwp/core': patch
---

Fixed an issue where persisted queries were not being enabled properly when setting the `usePersistedQueries` flag.
7 changes: 6 additions & 1 deletion packages/faustwp-core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions packages/faustwp-core/tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

1 comment on commit a419252

@headless-platform-by-wp-engine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out the recent updates to your Atlas environment:

App Environment URL Build
faustjs canary https://hg…wered.com ✅ (logs)

Learn more about building on Atlas in our documentation.

Please sign in to comment.