The Netlify Function, taken directly from a Netlify team member's example repo:
const { ApolloServer } = require('apollo-server-lambda')
const { createHttpLink } = require('apollo-link-http')
const fetch = require('node-fetch')
const { introspectSchema, makeRemoteExecutableSchema } = require('graphql-tools')
exports.handler = async function(event, context) {
/** required for Fauna GraphQL auth */
if (!process.env.FAUNADB_SERVER_SECRET) {
const msg = `
FAUNADB_SERVER_SECRET missing.
Did you forget to install the fauna addon or forgot to run inside Netlify Dev?
`
console.error(msg)
return {
statusCode: 500,
body: JSON.stringify({ msg })
}
}
const b64encodedSecret = Buffer.from(
process.env.FAUNADB_SERVER_SECRET + ':' // weird but they
).toString('base64')
const headers = { Authorization: `Basic ${b64encodedSecret}` }
/** standard creation of apollo-server executable schema */
const link = createHttpLink({
uri: 'https://graphql.fauna.com/graphql', // modify as you see fit
fetch,
headers
})
const schema = await introspectSchema(link);
const executableSchema = makeRemoteExecutableSchema({
schema,
link
})
const server = new ApolloServer({
schema: executableSchema
})
return new Promise((yay, nay) => {
const cb = (err, args) => (err ? nay(err) : yay(args))
server.createHandler()(event, context, cb)
})
}
Inside the component: (The faunadb schema is set up exactly from their example tutorial)
export default {
data() {
return {
test: {},
}
},
apollo: {
test: gql`
query {
allWarehouses {
data {
_id
name
address {
street
city
state
zipCode
}
}
}
}
`
}
}
From reading similar questions regarding the same error (but not the same stack), it could be related to something trying parse HTML as JSON. I've also seen that it could be solved with JSON.stringify, but I don't know where the hayhay I should apply it.
Any suggestions?
What is expected ?
A clean return
What is actually happening?
Browser console: Error Network error: JSON.parse: unexpected character at line 1 column 1 of the JSON data
This bug report is available on Nuxt community (#c273)
Version
v4.0.0-rc.19
Reproduction link
https://github.com/pachiraDIG/hub
Steps to reproduce
Repo
After several hours, I can't seem to pinpoint the cause of this error when running a query.
Config for @nuxt/apollo module:
The error is coming through the apollo module:
The Netlify Function, taken directly from a Netlify team member's example repo:
Inside the component: (The faunadb schema is set up exactly from their example tutorial)
From reading similar questions regarding the same error (but not the same stack), it could be related to something trying parse HTML as JSON. I've also seen that it could be solved with
JSON.stringify
, but I don't know where the hayhay I should apply it.Any suggestions?
What is expected ?
A clean return
What is actually happening?
Browser console:
Error Network error: JSON.parse: unexpected character at line 1 column 1 of the JSON data