apollo
apollo copied to clipboard
Relative API url doesn't work with SSR
Environment
- Operating System: Linux
- Node Version: v18.17.1
- Nuxt Version: 3.10.3
- CLI Version: 3.11.1
- Nitro Version: 2.9.4
- Package Manager: [email protected]
- Builder: -
- User Config: experimental, debug, ssr, css, formkit, components, modules, typescript, runtimeConfig, vite, nitro, tailwindcss, i18n, headlessui, apollo, unionen-apollo-codegen, graphqlServer, primevue, pinia, hooks, build
- Runtime Modules: @formkit/[email protected], @formkit/auto-animate/[email protected], @nuxtjs/[email protected], @nuxtjs/[email protected], [email protected], [email protected], @nuxtjs/[email protected], [email protected], @nuxt/test-utils/[email protected], @pinia/[email protected], @nuxtjs/[email protected]
- Build Modules: -
Describe the bug
I have a graphql resolver in the server portion of Nuxt, and its endpoint stored in an env variable. It works nicely when called from the client, but blows up when called on the server side.
It is possible to work around this by supplying the full URL in the env variable, but this is impractical for scenarios where I need the environment to answer to multiple domain names.
Expected behaviour
I would expect to be able to call the local endpoint.
Reproduction
No response
Additional context
No response
Logs
`{
operation: {
variables: { language: 'sv' },
extensions: {},
operationName: 'schoolOptions',
query: { kind: 'Document', definitions: [Array], loc: [Location] }
},
networkError: TypeError: Failed to parse URL from /api/nuxt/graphql
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[cause]: TypeError [ERR_INVALID_URL]: Invalid URL
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:611:13)
at new Request (node:internal/deps/undici/undici:7132:25)
at fetch2 (node:internal/deps/undici/undici:10715:25)
at Object.fetch (node:internal/deps/undici/undici:11574:18)
at fetch (node:internal/process/pre_execution:229:25)
at /home/filip/weahead/digitalist/unionen/frontend/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@apollo/client/link/http/createHttpLink.js:120:7
at new Subscription (/home/filip/weahead/digitalist/unionen/frontend/node_modules/.pnpm/[email protected]/node_modules/zen-observable/lib/Observable.js:197:34)
at Observable.subscribe (/home/filip/weahead/digitalist/unionen/frontend/node_modules/.pnpm/[email protected]/node_modules/zen-observable/lib/Observable.js:279:14)
at /home/filip/weahead/digitalist/unionen/frontend/node_modules/.pnpm/@[email protected][email protected][email protected][email protected]/node_modules/@apollo/client/link/context/index.js:20:45
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
input: '/api/nuxt/graphql',
code: 'ERR_INVALID_URL'
}
},
graphQLErrors: undefined,
forward: [Function (anonymous)]
}`
Also interested in this. Seems to be related (or duplicate?) of #507 , so this appears to have been an issue for quite some time.