Back to Refine

Hasura Example | REST API Integration in Refine v5

documentation/docs/examples/data-provider/hasura.md

3.25.01.2 KB
Original Source

Any REST or GraphQL custom backend work integrated with Refine. Refine Hasura GraphQL Data Provider comes out-of-the-box. Thanks to Refine, you can connect to your Hasura database and create special queries and use your data easily. This example shows in detail how you can use the data in your Hasura database with Refine project.

ID Data Type

By default, the data provider assume that your ID type is uuid, you can change this behavior by using the idType option. You can pass Int or uuid as the value of idType option or use function to determine the idType based on the resource name.

Passing 'Int' or 'uuid' to idType

This will allow you to determine the idType for all resources.

tsx
const myDataProvider = dataProvider(client, {
  idType: "Int",
});

Passing function to idType

This will allow you to determine the idType based on the resource name.

tsx
const idTypeMap: Record<string, "Int" | "uuid"> = {
  users: "Int",
  posts: "uuid",
};

const myDataProvider = dataProvider(client, {
  idType: (resource) => idTypeMap[resource] ?? "uuid",
});
<CodeSandboxExample path="data-provider-hasura" />