Need advice about which tool to choose?Ask the StackShare community!
GraphQL vs Hasura: What are the differences?
Introduction GraphQL and Hasura are both powerful tools used in web development. While GraphQL is a query language for APIs and a runtime for executing those queries with an existing data model, Hasura is an open-source engine that connects to various databases and auto-generates a GraphQL API. Although they have similarities in terms of providing a GraphQL interface, there are key differences between the two.
Schema Stitching: GraphQL allows combining multiple GraphQL schemas into a single cohesive schema, also known as schema stitching. This enables the composition of multiple APIs in a flexible manner. On the other hand, Hasura does not support schema stitching out of the box, as it focuses on generating a GraphQL API from an existing database schema.
Authentication and Authorization: GraphQL provides a flexible mechanism for handling authentication and authorization, allowing developers to define their own logic. Hasura, as a complementary tool to GraphQL, provides built-in role-based access control (RBAC) that integrates seamlessly with an existing authentication system. This simplifies the implementation of access control rules and permissions.
Real-time Subscriptions: GraphQL Subscriptions enable real-time data updates by establishing a persistent connection between the client and the server, allowing the server to push data to the client when changes occur. Hasura makes it easy to implement real-time subscriptions by setting up triggers on database events. GraphQL itself does not have built-in support for real-time subscriptions.
Database Tracking and Migrations: GraphQL does not provide built-in capabilities for tracking database changes or performing database migrations. Hasura, as a data layer tool, tracks changes made to the database schema and automates the generation of the GraphQL API. It also supports database migrations, making it easier to evolve the database schema over time.
Performance Optimization: GraphQL allows clients to specify exactly what data they need, reducing the problem of over-fetching or under-fetching. Hasura optimizes query execution by generating efficient SQL queries based on the GraphQL query. It further provides caching mechanisms and performance optimizations to enhance query execution speed.
Data Fetching from Multiple Sources: GraphQL supports fetching data from multiple sources, such as databases, REST APIs, and even other GraphQL APIs, by defining resolvers. Hasura, being a single-tool solution, primarily focuses on using database as a data source. While it can integrate with other APIs, fetching data from multiple sources may require additional implementation and configuration.
In Summary, although both GraphQL and Hasura provide a GraphQL interface, they differ in terms of schema stitching capabilities, authentication and authorization mechanisms, real-time subscriptions, database tracking and migrations, performance optimizations, and data fetching from multiple sources.
Pros of GraphQL
- Schemas defined by the requests made by the user75
- Will replace RESTful interfaces63
- The future of API's62
- The future of databases49
- Self-documenting13
- Get many resources in a single request12
- Query Language6
- Ask for what you need, get exactly that6
- Fetch different resources in one request3
- Type system3
- Evolve your API without versions3
- Ease of client creation2
- GraphiQL2
- Easy setup2
- "Open" document1
- Fast prototyping1
- Supports subscription1
- Standard1
- Good for apps that query at build time. (SSR/Gatsby)1
- 1. Describe your data1
- Better versioning1
- Backed by Facebook1
- Easy to learn1
Pros of Hasura
- Fast23
- Easy GraphQL subscriptions18
- Easy setup of relationships and permissions16
- Automatically generates your GraphQL schema15
- Minimal learning curve15
- No back-end code required13
- Works with new and existing databases13
- Instant production ready GraphQL12
- Great UX11
- Low usage of resources4
- Simple4
Sign up to add or upvote prosMake informed product decisions
Cons of GraphQL
- Hard to migrate from GraphQL to another technology4
- More code to type.4
- Takes longer to build compared to schemaless.2
- No support for caching1
- All the pros sound like NFT pitches1
- No support for streaming1
- Works just like any other API at runtime1
- N+1 fetch problem1
- No built in security1
Cons of Hasura
- Cumbersome validations3