Apollo GraphQL middleware for enabling edge caching on Layer0.
npm install @layer0/apolloAllows you derive the URL for apollo queries so you can prefetch them using @layer0/prefetch
``js
// apollo client configuration
import { createHttpLink } from '@layer0/apollo'
export default () => ({
defaultHttpLink: false,
link: createHttpLink({
uri: typeof window === 'undefined' ? process.env.SHOPIFY_GQL_ENDPOINT : '/api/graphql',
headers: { 'Access-Token': process.env.GQL_ACCESS_TOKEN },
}),
})
`
If you're using @nuxtjs/apollo, you can use the configuration above by linking it to theapollo config in your nuxt.config.js:
`js`
apollo: {
clientConfigs: {
default: '~/apollo.config.js' // path to the apollo client config shown above
}
}
`js
import { createApolloURL } from '@layer0/apollo'
const urlToPrefetch = createApolloURL(apolloClient, query, variables)
``