Netlify functions:create (Fauna w/ GraphQL option) does not show up in the FaunaDB Dashboard

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 3: netlify addons:list

RESULT:

  • | fauna | FaunaDB Cloud | 5d741a8ed6e05ec5f3e7ca35
  • | identity | Netlify Identity | 5d76a44c547979017630f3eb

ACTION 4: netlify addons:delete fauna

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:

MAIN PROBLEM NOW:

How can I get my Fauna DB with the schema populated in the Fauna Dashboard to work with my Netlify site?

netlify functions:create and netlify addons:auth fauna do not work together

1 Like

Hi Ryan – I’ve run into a similar issue. Did you find a way to fix this?

Same here, I’m encountering a similar issue as well.

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:

  1. netlify addons:create fauna
  2. netlify addons:auth fauna
  3. create your FaunaDB schema in the Console
  4. create a functions folder and add to netlify.toml in the build.functions block:
[build]
   functions = "functions"
  1. 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!

1 Like

I’m running into the same issue, and it seems it’s the command netlify addons:auth fauna that breaks the connection.

Running the following:

$ netlify functions:create fauna
$ netlify dev:exec functions/fauna-graphql/sync-schema.js

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:

fauna shell --secret=XXXXXXXXXXXXX

To get netlify dev:exec and netlify dev to work at-least locally:

  1. Go into Fauna and select your database

  2. Select the security tab and create a new key for “server”

  3. Use this key in development
    on mac
    export FAUNADB_SERVER_SECRET=YourFaunaDBKeyHere
    on windows
    set FAUNADB_SERVER_SECRET=YourFaunaDBKeyHere

  4. Add FAUNADB_SERVER_SECRET as an environment variable
    Netlify App

Hope that helps

1 Like

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.

Hey there!

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.

Hope this helps!

2 Likes