Customize /graphql endpoint to serve different schemas

Customize /graphql endpoint to serve different schemas


0

In Hasura, is there a way to customise the /graphql endpoint so that for customer 1, it serves a schema at /graphql/customer1 and serves another at /graphql/customer2 for customer 2?

Currently, all my schemas are displayed in /graphql endpoint and it creates clutter and also makes the data visible to all when used with the graphiql interface.

Also, I have created my custom data-connector using dc-agents, if that information is of any use

1 Answer
1


0

You may establish schema isolation and configure the /graphql endpoint for distinct clients in Hasura by utilizing a feature called "GraphQL Engine Roles and Remote Schemas. This enables you to specify roles and permissions for various schemas and APIs. In Hasura, assign roles to each client, such as customer1 and customer2. Assign different schemas to each role. Assign the customer1 schema to the customer1 role, and the customer2 schema to the customer2 role, for example. Set the permissions for each role to determine which operations (queries, changes) are permitted on their respective schemas. In your application code, customize the GraphQL endpoint URLs for each customer. You may, for example, create /graphql/customer1 and /graphql/customer2 endpoints to correspond to the various roles and schemas. You may additionally safeguard data accessibility via the GraphiQL interface by specifying role-based access permissions. Here’s how you may change the endpoint URLs in your application code.

// For customer 1
const customer1GraphQLURL = "/graphql/customer1";

// For customer 2
const customer2GraphQLURL = "/graphql/customer2";

// Use these URLs to make GraphQL requests for each customer.

You can ensure that each customer only communicates with their own schema and has their own GraphQL endpoint this way. You may incorporate your own data connection using dc-agents into the schema for each customer by giving the relevant schema to the associated role. You may restrict which roles have access to your custom data connection by configuring the permissions.

New contributor

diniramdhni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



Leave a Reply

Your email address will not be published. Required fields are marked *