Building a react-admin data provider for FaunaDB

225 Views Asked by At

With Graphcool being sunsetted, I've been trying to get react-admin to work with Fauna, but have not been successful. The Fauna GraphQL grammar is different than Graphcool, and of course when I connect to my Fauna DB, it doesn't recognize any of the resources.

If I build a very simple Fauna DB by uploading the following GraphQL schema:

type Location {
    name: String!
    address1: String!
    address2: String
    city: String
    state: String
    zip: String
}

type Query {
  allLocations: [ Location ]
}

The final schema that Fauna creates looks like:

directive @embedded on OBJECT
directive @collection(name: String!) on OBJECT
directive @index(name: String!) on FIELD_DEFINITION
directive @resolver(
  name: String
  paginated: Boolean! = false
) on FIELD_DEFINITION
directive @relation(name: String) on FIELD_DEFINITION
directive @unique(index: String) on FIELD_DEFINITION
scalar Date

type Location {
  city: String
  name: String!
  zip: String
  state: String
  _id: ID!
  address2: String
  address1: String!
  _ts: Long!
}

input LocationInput {
  name: String!
  address1: String!
  address2: String
  city: String
  state: String
  zip: String
}

type LocationPage {
  data: [Location]!
  after: String
  before: String
}

scalar Long

type Mutation {
  createLocation(data: LocationInput!): Location!
  updateLocation(
    id: ID!
    data: LocationInput!
  ): Location
  deleteLocation(id: ID!): Location
}

type Query {
  findLocationByID(id: ID!): Location
  allLocations(
    _size: Int
    _cursor: String
  ): LocationPage!
}

scalar Time

I'm having a hard time figuring out how to adapt the Graphcool/GraphQL data providers to account for the difference in the Fauna grammar. A couple of differences I've noticed:

  • Fauna names the IDs _id, but ra-data-graphcool expects them to be id
  • Fauna create/update mutations expect a single input object that mirrors the type

There are probably also differences in how the Graphcool data provider builds out the gql for getting record lists as well. Has anyone created or modified a data provider for Fauna (or maybe Back4App or other free/inexpensive cloud GraphQL providers)?

0

There are 0 best solutions below