Skip to content

Commit

Permalink
feat(apollo): upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Jul 17, 2022
1 parent 492a23f commit efca0e2
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 274 deletions.
13 changes: 3 additions & 10 deletions nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"test:visual": "WAIT_ON_TIMEOUT=600000 start-server-and-test 'pnpm storybook --ci' 6006 'sh ./.storybook/storycap/test.sh'"
},
"dependencies": {
"@apollo/client": "3.6.9",
"@dargmuesli/nuxt-clipboard2": "0.2.2",
"@dargmuesli/nuxt-cookie-control": "1.9.9",
"@http-util/status-i18n": "0.6.2",
Expand All @@ -47,15 +48,7 @@
"@tiptap/vue-2": "2.0.0-beta.84",
"@uppy/core": "2.3.1",
"@uppy/tus": "2.4.1",
"apollo-cache-inmemory": "1.6.6",
"apollo-client": "2.6.10",
"apollo-link": "1.2.14",
"apollo-link-context": "1.0.20",
"apollo-link-http": "1.5.17",
"apollo-link-http-common": "0.2.16",
"apollo-link-persisted-queries": "0.2.5",
"apollo-link-state": "0.4.2",
"apollo-upload-client": "13.0.0",
"apollo-upload-client": "17.0.0",
"chart.js": "3.8.0",
"consola": "2.15.3",
"cookie": "0.5.0",
Expand Down Expand Up @@ -113,7 +106,7 @@
"@storybook/core-events": "6.5.9",
"@storybook/theming": "6.5.9",
"@tiptap/core": "2.0.0-beta.182",
"@types/apollo-upload-client": "8.1.3",
"@types/apollo-upload-client": "17.0.1",
"@types/cookie": "0.5.1",
"@types/dompurify": "2.3.3",
"@types/html-to-text": "8.1.0",
Expand Down
42 changes: 17 additions & 25 deletions nuxt/plugins/apollo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Context } from '@nuxt/types-edge'
import { ApolloClient, ApolloClientOptions, Resolvers } from 'apollo-client'
import { ApolloLink, DocumentNode, from } from 'apollo-link'
import { setContext } from 'apollo-link-context'
import { createPersistedQueryLink } from 'apollo-link-persisted-queries'
import { HttpOptions } from 'apollo-link-http-common'
import { withClientState, ClientStateConfig } from 'apollo-link-state'
import {
InMemoryCache,
ApolloClient,
ApolloClientOptions,
ApolloLink,
DocumentNode,
from,
HttpOptions,
InMemoryCacheConfig,
NormalizedCacheObject,
} from 'apollo-cache-inmemory'
Resolvers,
} from '@apollo/client/core'
import { InMemoryCache } from '@apollo/client/cache'
import {
createPersistedQueryLink,
PersistedQueryLink,
} from '@apollo/client/link/persisted-queries'
import { setContext } from '@apollo/client/link/context'
import { createUploadLink } from 'apollo-upload-client'
import Vue from 'vue'
import VueApollo from 'vue-apollo'
Expand All @@ -21,7 +27,6 @@ import config from './apollo-config'
export interface ApolloClientClientConfig<TCacheShape> {
apollo?: ApolloClientOptions<TCacheShape>
cache?: InMemoryCache | false
clientState?: ClientStateConfig
defaultHttpLink?: boolean
httpEndpoint?: string
httpLinkOptions?: HttpOptions
Expand Down Expand Up @@ -124,9 +129,9 @@ export default (ctx: Context) => {
app.apolloProvider = apolloProvider

if (process.server) {
const apolloSSR = require('vue-apollo/ssr')
const ApolloSSR = require('vue-apollo/ssr')
beforeNuxtRender(({ nuxtState }) => {
nuxtState.apollo = apolloSSR.getStates(apolloProvider)
nuxtState.apollo = ApolloSSR.getStates(apolloProvider)
})
}
}
Expand Down Expand Up @@ -161,7 +166,6 @@ export function createApolloClient<TCacheShape>(
const {
apollo,
clientId,
clientState,
defaultHttpLink,
httpEndpoint,
httpLinkOptions,
Expand Down Expand Up @@ -230,7 +234,7 @@ export function createApolloClient<TCacheShape>(
}

if (!disableHttp) {
let persistingOpts = {}
let persistingOpts = {} as PersistedQueryLink.Options
if (typeof persisting === 'object' && persisting != null) {
persistingOpts = persisting
persisting = true
Expand All @@ -241,18 +245,6 @@ export function createApolloClient<TCacheShape>(
}
}

if (clientState && link) {
consola.warn(
'clientState is deprecated, see https://vue-cli-plugin-apollo.netlify.com/guide/client-state.html'
)
stateLink = withClientState({
cache,
...clientState,
resolvers: undefined,
})
link = from([stateLink, link])
}

const apolloClient = new ApolloClient({
link,
cache,
Expand Down
Loading

0 comments on commit efca0e2

Please sign in to comment.