Netlify not writing my FaunaDb, I cannot save my users into the database

I simply don’t understand why I can’t get users in my FaunaDB using netlify. A user is created in Netlify, and Stripe, but not FaunaDB.

I have checked the URL endpoint, checked my api keys, tried all regions, changed the URL endpoint to be region specific but nothing is working.

I have a mutation like this:

  // store the Netlify and Stripe IDs in Fauna
  await faunaFetch({
    query: `
      mutation ($netlifyID: ID!, $stripeID: ID!) {
        createUser(data: { netlifyID: $netlifyID, stripeID: $stripeID }) {
          netlifyID
          stripeID
        }
      }
    `,
    variables: {
      netlifyID: user.id,
      stripeID: customer.id,
    },
  });

  return {
    statusCode: 200,
    body: JSON.stringify({
      app_metadata: {
        roles: ['free'],
      },
    }),
  };

Please anyone check my code in this repo?

REPO

I appreciate your time and help.

Without actually running your code, I think the problem is in your GraphQL schema definition.

The file db/schema.gql contains:

type User {
  netlifyID: ID!
  stripeID: ID!
}

type Query {
  getUserByNetlifyID(netlifyID: ID!): User!
  getUserByStripeID(stripeID: ID!): User!
}

The ID type is a Fauna document ID, which is a string-encoded 64-bit integer. If the Netlify and/or Stripe ids are not that type, your query would fail.

Likely, the simplest thing to do would be to update your schema to use the String type:

type User {
  netlifyID: String!
  stripeID: String!
}

type Query {
  getUserByNetlifyID(netlifyID: String!): User!
  getUserByStripeID(stripeID: String!): User!
}

I would suggest verifying that the GraphQL mutation from your example works in the Dashboard’s GraphQL page before making any adjustments to your app logic. Just replace the dynamic bits with static values that represent actual Netlify/Stripe ids.

1 Like

Thank you very much for your responce, I went to check my DB and boom! The user was there, that’s why I had deleted the topic.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.