Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions docs/content/1.getting-started/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default defineNuxtConfig({
authHeader: 'Authorization',
tokenStorage: 'cookie',
proxyCookies: true,
clients: {}
clients: {},
useApolloUploadLink: true
}
})
```
Expand Down Expand Up @@ -76,7 +77,8 @@ export default defineNuxtConfig({
tokenName: 'apollo:<client-name>.token',
tokenStorage: 'cookie',
authType: 'Bearer',
authHeader: 'Authorization'
authHeader: 'Authorization',
useApolloUploadLink: true
},
other: './apollo/other.ts'
}
Expand All @@ -100,7 +102,8 @@ export default defineApolloClient({
tokenName: 'apollo:<client-name>.token',
tokenStorage: 'cookie',
authType: 'Bearer',
authHeader: 'Authorization'
authHeader: 'Authorization',
useApolloUploadLink: true
})
```
::
Expand Down Expand Up @@ -166,3 +169,10 @@ Specify the Authentication scheme.
- Default: `Authorization`

Name of the Authentication token header.

- ### `useApolloUploadLink`

- Default: `true`

Specify if the client should use `apollo-upload-client` for file uploads. This is required for file uploads.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@rollup/plugin-graphql": "^2.0.5",
"@vue/apollo-composable": "^4.2.2",
"@vue/apollo-option": "^4.2.2",
"apollo-upload-client": "^18.0.1",
"defu": "^6.1.4",
"destr": "^2.0.5",
"graphql": "^16.11.0",
Expand Down
5 changes: 4 additions & 1 deletion playground/apollo/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ export default defineApolloClient({

// Specify if the client should solely use WebSocket.
// requires `wsEndpoint`.
websocketsOnly: false
websocketsOnly: false,

// Specify if the client should use `apollo-upload-client` for file uploads.
useApolloUploadLink: true
})
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default defineNuxtModule<ModuleOptions>({
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax'
},
clientAwareness: false
clientAwareness: false,
useApolloUploadLink: true
},
async setup(options, nuxt) {
if (!options.clients || !Object.keys(options.clients).length) {
Expand Down Expand Up @@ -84,6 +85,7 @@ export default defineNuxtModule<ModuleOptions>({
v.authHeader = v?.authHeader || options.authHeader
v.tokenName = v?.tokenName || `apollo:${k}.token`
v.tokenStorage = v?.tokenStorage || options.tokenStorage
v.useApolloUploadLink = v?.useApolloUploadLink || options.useApolloUploadLink
if (v.cookieAttributes) {
v.cookieAttributes = defu(v?.cookieAttributes, options.cookieAttributes)
}
Expand Down
8 changes: 6 additions & 2 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getMainDefinition } from '@apollo/client/utilities'
import { createApolloProvider } from '@vue/apollo-option'
import { ApolloClients, provideApolloClients } from '@vue/apollo-composable'
import { ApolloClient, ApolloLink, createHttpLink, InMemoryCache, split } from '@apollo/client/core'
import uploadHttpLink from 'apollo-upload-client/createUploadLink.mjs'
import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
import { setContext } from '@apollo/client/link/context'
import type { ClientConfig, ErrorResponse } from '../types'
Expand Down Expand Up @@ -73,11 +74,14 @@ export default defineNuxtPlugin((nuxtApp) => {
}
})

const httpLink = authLink.concat(createHttpLink({
const httpLinkOptions = {
...(clientConfig?.httpLinkOptions && clientConfig.httpLinkOptions),
uri: (import.meta.client && clientConfig.browserHttpEndpoint) || clientConfig.httpEndpoint,
headers: { ...(clientConfig?.httpLinkOptions?.headers || {}) }
}))
}

// Apollo Http Client
const httpLink = clientConfig.useApolloUploadLink ? authLink.concat(uploadHttpLink(httpLinkOptions)) : authLink.concat(createHttpLink(httpLinkOptions))

let wsLink: GraphQLWsLink | null = null

Expand Down
14 changes: 14 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ export type ClientConfig = {
* Configuration for the auth cookie.
*/
cookieAttributes?: CookieAttributes

/**
* Use 'apollo-upload-client' for file uploads, instead of the standard apollo HttpLink.
* @type {boolean}
* @default true
*/
useApolloUploadLink?: boolean
}

export interface NuxtApolloConfig<T = false> {
Expand Down Expand Up @@ -165,4 +172,11 @@ export interface NuxtApolloConfig<T = false> {
* @default false
*/
clientAwareness?: boolean

/**
* Use 'apollo-upload-client' for file uploads, instead of the standard apollo HttpLink.
* @type {boolean}
* @default true
*/
useApolloUploadLink?: boolean
}