Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonbahl/063507f4f9d9afb1dbd97083b99d7ae7 to your computer and use it in GitHub Desktop.
Save jasonbahl/063507f4f9d9afb1dbd97083b99d7ae7 to your computer and use it in GitHub Desktop.
Faust.js plugin for adding Automated Persisted Query support. Plays nice with https://github.com/wp-graphql/wp-graphql-smart-cache
import {createPersistedQueryLink} from '@apollo/client/link/persisted-queries';
import {HttpLink} from "@apollo/client";
import {sha256} from 'crypto-hash';
const linkChain = createPersistedQueryLink({ sha256 }).concat(
new HttpLink({ uri: process.env.WPGRAPHQL_URL }),
);
class PersistedQueriesPlugin {
apply({ addFilter }) {
addFilter('apolloClientOptions', 'faust', (apolloClientOptions) => {
const existingLink = apolloClientOptions?.link;
return {
...apolloClientOptions,
link: existingLink ? linkChain.concat(existingLink) : linkChain
}
});
}
}
export default PersistedQueriesPlugin;
@blakewilson
Copy link

💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment