GraphQL is a query language for API, and a server-side runtime for executing queries using a type system define for data. GraphQL isn't tied to any specific database or storage engine and is instead backed by existing code and data.
GraphQL is a new API standard that provides a more efficient, powerful, and flexible alternative to REST. It was developed and open sourced by Facebook and is now maintained by a large community of companies and individuals from all over the world.
At its core, GraphQL enables declarative data fetching where a client can specify exactly what data it needs from an API.
Instead of multiple endpoints that return fixed data structures, a GraphQL server only exposes a single endpoint and responds with precisely the data that a client asked for.
- Prisma creates tools and that replaces traditional ORMs. Prisma enriches the GraphQL ecosystem and community by creating high-quality tools and software.
- Hasura is an open source engine that connects to your databases & microservices and auto-generates a production-ready GraphQL backend. Hasura gives you realtime GraphQL APIs that are high-performance, scalable, extensible & secure (with authorization baked in).
Over-Fetching and Under-Fetching
api/users/{id}
api/users/{id}/posts
api/users/{id}/followers
- 🏆graphql-dotnet/graphql-dotnet
- ⭐ChilliCream/hotchocolate
- STEP #1:
dotnet add package HotChocolate.AspNetCore
- STEP #2: Define the types
- STEP #3: Add a Query type
- STEP #4: Add GraphQL services
builder.Services .AddGraphQLServer() .AddQueryType<Query>();
- STEP #5: Map the GraphQL endpoint
var app = builder.Build(); // map GraphQL app.MapGraphQL(); app.Run();
- STEP #1:
Operation | GraphQL | REST |
---|---|---|
Read | Query | GET |
Write | Mutation | PUT, POST, PATCH, DELETE |
Event | Subscription | N/A |