Migrate GraphQL to Hasura Data Delivery Network
On this page
Important
Always refer to the official documentation of both MongoDB Atlas and Hasura for the most up-to-date and accurate information. Specific steps may vary depending on the details of your project and the technologies used.
Hasura empowers developers to rapidly build and deploy GraphQL and REST APIs on MongoDB and many other data sources. By radically cutting down API development times, Hasura enables rapid access to data, reduces friction across teams and services, and enables enterprises to shorten time to market on data-powered products and features.
Before You Begin
If you haven't already, Create an account on Hasura's website cloud.hasura.io.
Migrate to Hasura
Migrating your GraphQL API endpoints from MongoDB Atlas App Services to Hasura is a multi-step process that encompasses setting up your environment in Hasura, configuring database connections, migrating schemas, and implementing authorization and authentication mechanisms. Below is an expanded guide detailing each step, with a focus on authorization and role-based access control (RBAC) within Hasura. For more information, check out the Hasura docs.
To migrate to Hasura:
Authorize Hasura for MongoDB
Hasura can connect to a new or existing MongoDB Atlas database and generate the GraphQL API for you.
Go to cloud.mongodb.com
and navigate to the Network Access page on the
Atlas dashboard.
Click the ADD IP ADDRESS button and enter 0.0.0.0/0
.
Describe this entry as Hasura. For a unique IP address, contact Hasura
sales about deploying on Private DDN.
Now, Hasura Cloud can communicate with your MongoDB Atlas instance.
On the Database page, find the Atlas cluster that is connected to your App Services app and click on Connect. Select the Drivers option and copy the connection string.
Create a new project and connect to Hasura
The Hasura docs contain the details to perform the following steps:
Install CLI (Prerequisites)
Log in using the CLI
Initialize a new supergraph in an empty directory
Connect to data
Introspect your data source
Build your local supergraph
Start your supergraph
Create a Hasura cloud project
Build and deploy your supergraph
Test Your GraphQL Queries
You can use the API Explorer page on the Hasura Console to test out some GraphQL queries.
Hasura also uses the GraphiQL interface, which is similar to how you test queries in Atlas App Services.
Authorization and Authentication
Hasura does not directly handle authentication. Instead, it relies on session variables provided by an external authentication service. These session variables include user, role, and organization information crucial for determining data access rights. For details, refer to the Hasura authentication docs
Data access permissions, including roles and rule expressions, can be converted into Hasura role-based permission rules.
All Authentication methods that Atlas provides are compatible with Hasura's Webhook and JWT auth methods. If you are using Email/Pass, Anonymous, or API Key authentication, use Hasura Webhook. If you are using a Custom JWT, integrate directly with Hasura's JWT auth method.
Hasura recommends using an external IdP for managing authentication processes for enhanced security and flexibility. You can integrate Hasura with any authentication provider of your choice, such as Auth0, Firebase Auth, AWS Cognito, or even a custom solution, to verify the user and set the necessary session variables. For configuring JWT or webhook authentication in Hasura, refer to the documentation at:
Set Up Custom Resolvers or Business Logic
If your existing GraphQL API endpoints include custom resolvers or business logic, you'll need to implement these in Hasura. Hasura supports:
Remote schemas through its GraphQL Connector
Custom queries through Native Queries for MongoDB
Custom mutations through Native Mutations for MongoDB
Custom business logic through TypeScript
Update Client Applications
Update any client applications that interact with your GraphQL API endpoints to point to the new Hasura endpoint URLs. Any existing Apollo client will work with Hasura. Refactor your application GraphQL queries and mutations to align with Hasura syntax and schema, ensuring compatibility with the new GraphQL API structure.
Shut down MongoDB Atlas App Services Endpoints
Once you have verified that your GraphQL API endpoints are fully migrated and operational on Hasura, you can delete your MongoDB Atlas App Services app to avoid unnecessary costs. As a reminder, Atlas GraphQL endpoints will no longer be supported beginning March 12, 2025.