GraphQL on ASP.NET Core
WITH
Who are we?
Who is this for?Who is this for?
demo.chillicream.com
query {
me {
name
age
}
}
{
"me": {
"name": "Foo",
"age": 99
}
}
GET
https://webservices.amazon.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=mY-Sup3r-s3cr3!-k3y&
AssociateTag=12345&
Operation=ItemLookup&
ItemId=0316067938&
ResponseGroup=Reviews&
TruncateReviewsAt=256&
IncludeReviewsSummary=False&
Version=2013-08-01&
Timestamp=[YYYY-MM-DDThh:mm:ssZ]&
Signature=[Request Signature]
What is GraphQL?
GraphQL
No over- or under-fetching
One Request
Type System
No versioning
Simplicity
One Endpoint
Documentation
Real-time
Predictability
What GraphQL is not:
• Graph database query language
• Solution for binary streams
• Facebooks version of OData
• Bound to a specific data source
• Limited to HTTP
• Limited to the JavaScript world
• A good solution for a health
check endpoint.
REST GraphQL
Shared Definition No Yes
Conceptual Model Resources Graphs
Organization Federated Centralized
Related Ops Yes No
Introspection No Yes
Data Typing Weak Strong
Real-Time No Yes
GraphQL Operations:
• Query = Read
• Mutation = Write
• Subscription = Events
Demo
Resolvers and Pipelines
Demo
query {
me {
friends {
friends {
friends {
name
}
}
}
}
}
Demo
Scaling Your Graph
query {
me {
name
age
}
}
query {
me {
name
age
friends {
name
age
}
}
}
query {
me {
friends {
friends {
friends {
name
}
}
}
}
}
query {
me {
name
stories(first: 10) {
... Content
}
}
}
query {
me {
name
stories(first: 10000) {
... Content
}
}
}
type User {
stories(first: PaginationAmount): [Story!]!
}
SchemaBuilder.New()
.AddType(new PaginationAmountType(50))
...
.Create();
type User {
stories(first: Int): [Story!]!
}
type User {
stories(first: PaginationAmount): [Story!]!
@cost(complexity: 5)
}
type User {
stories(first: PaginationAmount): [Story!]!
@cost(complexity: 5 multipliers:[first])
}
1
1 50
me
Stories(first: 10)name
1
1 5000
me
Stories(first: 1000)name
Demo
Persisted Queries
GraphQL Client GraphQL Server
High Bandwidth Usage
{
"query" : <query>
}
GraphQL Client GraphQL Server
Unrestricted Query Execution
{
"query" : <query>
}
GraphQL Client GraphQL Server
Low Bandwidth Usage
{
“id” : “W5IYenw==”
}
Middleware
GraphQL Client GraphQL Server
Restricted Query Execution
{
“id” : “W5IYenw==”
}
Middleware
Demo
Testing Your Schema
Demo
How can we do microservices with
that?
What is
schema
stitching?
The capability to merge multiple
GraphQL schemas into one
schema.
Hot Chocolate Gateway
Hot Chocolate GraphQL
Mongo DBRaven DB
Abritray REST Endpoint
{REST}
SQL Server
query {
me {
messages {
# Hot Chocolate GraphQL
text
# Apollo Server
createdBy {
name
}
# Abritray REST Endpoint
views
likes
replies
}
}
}
One GraphQL Query
Apollo GraphQL
Demo
Where do you find us?
https://github.com/ChilliCream
https://chillicream.com
https://hotchocolate.io
https://twitter.com/Chilli_Cream

.NET Fest 2019. Michael Staib. Hot Chocolate: GraphQL Schema Stitching with ASP.Net Core

Editor's Notes

  • #8 https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm