apollo icon indicating copy to clipboard operation
apollo copied to clipboard

Relative API url doesn't work with SSR

Open filiphazardous opened this issue 10 months ago • 1 comments

Environment

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)]
}`

filiphazardous avatar Apr 04 '24 09:04 filiphazardous

Also interested in this. Seems to be related (or duplicate?) of #507 , so this appears to have been an issue for quite some time.

pixleight avatar Apr 04 '24 15:04 pixleight