Created
October 25, 2022 15:13
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a plugin that adds support for Apollo's Automated Persisted Queries.
Plays nice with https://github.com/wp-graphql/wp-graphql-smart-cache
To add, you need to update the faust.config.js like so: