Hello. Thank you for any help you can provide here is a detail of the goal I am trying to achieve, the steps that I have taken to try and achieve this goal, and the error messages that have come along the way.
** I have gone through all of this with the FaunaDB support team, and we are confident it is a porblem with Netlify and not on the Fauna Addon side **
GOAL: To be able to see the FaunaDB (GraphQL) database that was created with netlify functions:create in the Fauna dashboard
ACTION 1: netlify addons:auth fauna
RESULT:
The Fauna dashboard did populate with the schema from my Netlify Functions schema
BUT then on netlify dev I get the following error message:
Response with status 500 in 264 ms. ◈ Error during invocation: [ { message: ‘Ref refers to undefined database 'backend'’, extensions: { code: ‘invalid ref’ } } ]
ACTION 2: because ‘backend’ was undefined I deleted that DB in the newly populated Fauna Dashboard
RESULT:
When I run netlify dev now I get the following error message:
◈ Error during invocation: [ { message: ‘Invalid database secret.’ } ] Request from ::1: POST /.netlify/functions/backend Response with status 500 in 234 ms.
ACTION 5: netlify addons:create fauna && netlify addons:auth fauna AND I update my schema.graphql file inside the Fauna Dashboard
RESULT:
Now again my Fauna database is populated in the Fauna dashboard.
BUT now the problem is all of my queries are still trying to hit the /.netlify/functions/backend directory that was created in when I followed the old way of netlify:functions create
AND when I run netlify dev the project is still injecting my old credentials into the site:
◈ Netlify Dev ◈
◈ Injected addon env var: FAUNADB_ADMIN_SECRET
◈ Injected addon env var: FAUNADB_SERVER_SECRET
◈ Injected addon env var: FAUNADB_CLIENT_SECRET
◈ Starting Netlify Dev with gatsby
Waiting for localhost:8000.
◈ Lambda server is listening on 34567
ACTION 6: I deleted the /.netlify/functions/backend directory from my local files. And I even deleted my whole Netlify site. Created a new netlify site from the same git and local directory.
RESULT:
And now I am getting errors on Netlify Functions and Identity:
Hey there! I’m Lewis, a PM with Fauna. I’ve been chatting with the Netlify team about this.
Please try to create the function that you need in JS. netlify functions:create uses prebundled templates that probably doesn’t match the schema you are using
Try this:
netlify addons:create fauna
netlify addons:auth fauna
create your FaunaDB schema in the Console
create a functions folder and add to netlify.toml in the build.functions block:
[build]
functions = "functions"
Add the code needed to functions/whatever-function-name.js that talks to FaunaDB
Please let us know if this is helpful, and happy to continue helping on the Fauna side!
The request to https://graphql.fauna.com/import returns:
Use the following HTTP header to connect to the FaunaDB GraphQL API:
{ "Authorization": "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }
My app can connect to the db just fine through the Netlify function and I can query it using Apollo devtools.
However, as soon as I run:
$ netlify addons:auth
The database now shows in my FaunaDB dashboard but the request to https://graphql.fauna.com/import from running netlify dev:exec functions/fauna-graphql/sync-schema.js now returns:
Ref refers to undefined database 'e7f3f6ea-1d89-41b3-a4ea-d2b214793582'
And Netlify Dev logs this error when my app tries to use the function exactly like before:
Error during invocation: [ { message:
'Ref refers to undefined database \'e7f3f6ea-1d89-41b3-a4ea-d2b214793582\'',
extensions: { code: 'invalid ref' } } ]
I know it’s not a problem with the environment variables not being injected correctly or being outdated, because if I log the server secret and use it to connect to the db through the Fauna shell, it works fine:
That’s what I ended up doing, basically setting up the database manually instead of using the addon. It kind of defeats the purpose of having the addon though.
A fix for netlify addons:auth fauna breaking the connection went live this morning. Note: the fix only works for new integrations since FaunaDB does not have the power to update Netlify env variables after the import.