Getting started with
GraphQL on ASP.NET Core

Michael Staib

{
  me {
    name
  }
}
{
  "me": {
    "name": "Michael Staib"
  }
}
{
  me {
    name
  }
}
{
  me {
    name
    image {
      width
      height
      url
    }
  }
}
{
  "me": {
    "name": "Michael Staib",
    "image": {
      "width": 200,
      "height": 300,
      "url": "http://some/images/123.png"          
    }
  }
}
{
  me {
    name
    image {
      width
      height
      url
    }
  }
}
{
  me {
    name
    lastSeen
    friends {
      name
      lastSeen
    }
  }
}
{
  "me": {
    "name": "Michael Staib",
    "lastSeen": "2018-05-19T18:45",
    "friends": [
      {
        "name": "Rafael Staib",
        "lastSeen": "2018-05-24T12:37"
      },
      {
        "name": "Pascal Senn",
        "lastSeen": "2018-06-07T17:13"
      }
    ]
  }
}
{
  me {
    name
    lastSeen
    friends {
      name
      lastSeen
    }
  }
}
{
  "me": {
    "name": "Michael Staib",
    "lastSeen": "2018-05-19T18:45",
    "friends": [
      {
        "name": "Rafael Staib",
        "lastSeen": "2018-05-24T12:37"
      },
      {
        "name": "Pascal Senn",
        "lastSeen": "2018-06-07T17:13"
      }
    ]
  }
}
{
  me {
    ... PersonInfo
    friends {
      ... PersonInfo
    }
  }
}
fragment PersonInfo on Person {
  name
  lastSeen
}
  • One Endpoint
  • One Request
  • No over- or under-fetching
  • Type System
  • Predictable

Understanding Field Middleware

[UseDbContext(typeof(BookContext))]
[UsePaging]
public IQueryable<Book> GetBooks(
    [ScopedService] BookContext context) => 
    context.Books;
protected override void Configure(
    IObjectTypeDescriptor<Query> descriptor)
{
    descriptor
        .Field(t => t.GetBooks())
        .UseDbContext<BookContext>()
        .UsePaging();
}
descriptor.Use(next => async context =>
{
    // logic
    
    await next(context);

    // more logic
})

DataLoader

https://chillicream.com

https://github.com/chillicream/hotchocolate

Channel 9 - Getting started with GraphQL on .NET

By Michael Ingmar Staib

Channel 9 - Getting started with GraphQL on .NET

  • 582