Demo application and slides for a GraphQL API in .NET 5. Used to demonstrate core differences between GraphQL and REST. Used as a reference implementation for the talk Writing GraphQL API's with .NET 5.
The application inside /src
is a simple newsfeed API with support for
- Getting a list of stories a.k.a. the newsfeed
- Getting the authors for the stories
- Getting the stories for a specific author
- Adding new authors
- Adding new stories
- Subscribing to new newsfeed stories
This demo application contains a working subscription, implemented with GraphQL.SystemReactive
. Follow these steps to add subscriptions to your own GraphQL/.NET 5 API:
- Run
dotnet nuget add GraphQL.SystemReactive
- Add an
IObservable<T>
that the GraphQL subscription can listen to. See MockNewsfeedData.cs. - Add a GraphQL subscription that resolves the
IObservable<T>
. See NewsfeedSubscription.cs. - Register the subscription with the GraphQL schema. See NewsfeedSchema.cs.
- Add a custom
DocumentExecuter
that supports theSubscriptionExecutionStrategy
. See DocumentExecuterWithSubscriptions.cs. - Register the custom
DocumentExecuter
along with WebSockets and GraphQL WebSockets. See Startup.cs.
cd /src
dotnet run
Open a browser and navigate to https://localhost:5001/ui/playground
- Give a comparison between GraphQL and REST
- Provide background and reasoning for Facebook's development of the GraphQL specification
- Point out a few problems with REST that are mitigated with GraphQL
- Over-fetching
- Multiple round trips
- API documentation
- Show, in code, how these problems are tackled with GraphQL