https://github.com/liteobject/demo.graphql
Demo GraphQL with C#
https://github.com/liteobject/demo.graphql
api csharp graphql hotchocolate
Last synced: 8 months ago
JSON representation
Demo GraphQL with C#
- Host: GitHub
- URL: https://github.com/liteobject/demo.graphql
- Owner: LiteObject
- Created: 2022-09-06T13:42:24.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-01T17:20:38.000Z (over 2 years ago)
- Last Synced: 2024-12-29T18:22:23.595Z (9 months ago)
- Topics: api, csharp, graphql, hotchocolate
- Language: C#
- Homepage:
- Size: 41 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Demo GraphQL with C#
> 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.
## Tools
- [Prisma](https://www.prisma.io/) creates tools and that replaces traditional ORMs. Prisma enriches the GraphQL ecosystem and community by creating high-quality tools and software.
- [Hasura](https://hasura.io/) 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).## GraphQL vs REST API
Over-Fetching and Under-Fetching```html
api/users/{id}
api/users/{id}/posts
api/users/{id}/followers
```---
## There are two libraries to expose GraphQL endpoint:
- :trophy:[graphql-dotnet/graphql-dotnet](https://graphql-dotnet.github.io/docs/getting-started/introduction/)
- :star:[ChilliCream/hotchocolate](https://github.com/ChilliCream/hotchocolate/blob/main/website/src/docs/hotchocolate/get-started.md)
- STEP #1: `dotnet add package HotChocolate.AspNetCore`
- STEP #2: Define the types
- STEP #3: Add a Query type
- STEP #4: Add GraphQL services
```csharp
builder.Services
.AddGraphQLServer()
.AddQueryType();
```
- STEP #5: Map the GraphQL endpoint
```csharp
var app = builder.Build();
// map GraphQL
app.MapGraphQL();
app.Run();
```---
## Operations: GraphQL vs REST
|Operation| GraphQL | REST |
|:---|:---|:---|
| Read | Query | GET |
| Write | Mutation | PUT, POST, PATCH, DELETE |
| Event | Subscription | N/A |---
## Links:
- [The Fullstack Tutorial for GraphQL](https://www.howtographql.com/)
- [Code using GraphQL](https://graphql.org/code/#c-net)
- [Next-generation Node.js and TypeScript ORM](https://www.prisma.io/)
- [Hasura](https://hasura.io/)
- [github.com/graphql/graphql-playground](https://github.com/graphql/graphql-playground)
- [GraphQL for .NET](https://github.com/graphql-dotnet/graphql-dotnet)
- [ChilliCream/hotchocolate-examples](https://github.com/ChilliCream/hotchocolate-examples)
- [ChilliCream/graphql-workshop](https://github.com/ChilliCream/graphql-workshop)