Files
dancefinder-app/app/plugins/apollo.ts
T
argoyle adf0cc4ac6
dancefinder-app / build (push) Successful in 1m18s
dancefinder-app / deploy-prod (push) Successful in 1m25s
chore(deps): remove deprecated subscriptions-transport-ws (#2922)
Removes the deprecated `subscriptions-transport-ws` package (Renovate dependency dashboard #49).

The package is unmaintained and was only reachable through the Apollo `WebSocketLink` in `app/plugins/apollo.ts`. The schema has no `Subscription` type and no subscription operations are defined, so the ws `split()` branch was dead code.

- Drop `WebSocketLink`, the `split()` routing, `getMainDefinition`, and `wsUrl` from `app/plugins/apollo.ts`
- Remove the direct `subscriptions-transport-ws` dependency

Verified with `npm run build` (green) and eslint (clean).

Note: the package lingers in the lockfile as an optional peer dep of `@apollo/client` v3; it disappears with the Apollo Client v4 upgrade, which removes `@apollo/client/link/ws` entirely.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-on: #2922
2026-05-25 10:54:17 +00:00

96 lines
2.7 KiB
TypeScript

import { ApolloClient, ApolloLink, createHttpLink, from, InMemoryCache } from '@apollo/client/core'
import { setContext } from '@apollo/client/link/context'
import type { GetTokenSilentlyOptions } from '@auth0/auth0-spa-js'
import type { Auth0VueClient } from '@auth0/auth0-vue'
import { SpanKind, TraceFlags } from '@opentelemetry/api'
import { DefaultApolloClient, provideApolloClient } from '@vue/apollo-composable'
import { defineNuxtPlugin, useNuxtApp } from '#app'
import { envConfig } from '~/utils/environment'
const apiUrl = envConfig(window.location.hostname).apiUrl
const cache = new InMemoryCache({
typePolicies: {
},
})
const STALE_AUTH_ERRORS = new Set([
'login_required',
'consent_required',
'interaction_required',
'invalid_grant',
'missing_refresh_token',
])
const getToken = async (options: GetTokenSilentlyOptions) => {
const nuxtApp = useNuxtApp()
const auth0: Auth0VueClient = nuxtApp.$auth0 as Auth0VueClient
return await auth0.getAccessTokenSilently(options).catch((err) => {
const code = err && typeof err === 'object' && 'error' in err ? (err as { error?: string }).error : undefined
if (code && STALE_AUTH_ERRORS.has(code)) {
auth0.logout({ openUrl: false }).catch(() => {})
}
return undefined
})
}
const httpLink = createHttpLink({
uri: apiUrl,
})
const authLink = setContext(async (_, { headers }) => {
return await getToken({}).then((token) => ({
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
},
}))
})
const createSpanLink = new ApolloLink((operation, forward) => {
const nuxtApp = useNuxtApp()
if (nuxtApp.$faro) {
const { trace } = nuxtApp.$faro.api.getOTEL()
const span = trace.getTracer('default').startSpan(`gql.${operation.operationName}`, {
kind: SpanKind.INTERNAL, // 0: Internal, 1: Server, 2: Client, 3: Producer, 4: Consumer
})
const spanContext = span.spanContext()
const traceParent = '00' + '-' + spanContext.traceId + '-' + spanContext.spanId + '-0' + Number(spanContext.traceFlags || TraceFlags.NONE).toString(16)
operation.setContext({ span, headers: { ...operation.getContext().headers, 'traceparent': traceParent } })
return forward(operation).map((data) => {
span.end()
return data
})
}
return forward(operation)
})
const link =
from([
createSpanLink,
authLink.concat(httpLink),
])
const instance = new ApolloClient({
devtools: {
enabled: true,
},
link,
cache,
defaultOptions: {
query: {
fetchPolicy: 'cache-first',
},
watchQuery: {
fetchPolicy: 'cache-and-network',
},
},
})
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.provide(DefaultApolloClient[Symbol.toStringTag], instance)
provideApolloClient(instance)
})