Hi
I am implementing an Apollo graphql server using a Netlify lambda. The graphql client is configured to use process.env.DEPLOY_URL
or http://localhost:8888
, in this way:
const host = process.env.hasOwnProperty('DEPLOY_URL') ? process.env.DEPLOY_URL : 'http://localhost:8888';
const link = createHttpLink({
fetch, // Switches between unfetch & node-fetch for client & server.
uri: `${host}/.netlify/functions/gql_server`
});
Local server in http://localhost:8888/.netlify/functions/gql_server works without issues with netlify dev
: the frontend code can query the server and get data, the same as the Graphql Playground.
However, the build process in deployment fails with a json error,
{ ServerParseError: Unexpected token N in JSON at position 0
at JSON.parse (<anonymous>)
at /opt/build/repo/node_modules/apollo-link-http-common/lib/index.js:35:25
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'ServerParseError',
response:
Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: [Object],
[Symbol(Response internals)]: [Object] },
statusCode: 404,
bodyText: 'Not Found' }
I have tried using DEPLOY_PRIME_URL
and URL
with the same results. I tried the settings recommended in the official Apollo documentation, a relative path, but my app uses Server Side Rendering and in this case the build fails with the error Error: only absolute urls are supported
.
I understand the error, the URI is wrong and the resulting response Not Found
is not a valid Json. However, after all these tests I still don’t know what is the right URI for the deployment of the lambda functions. Can anybody give me a hint about the right value I should use?
Edit: my netlify.toml is
[build]
functions = "src/functions"
Thank you,
ZSC