Skip to content

tarekmansour/HotChocolate-GraphQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HotChocolate-GraphQL

Creating a GraphQL .NET server with Hot Chocolate

What is GraphQL?

  • One Endpoint
  • One Request
  • Type System
  • Predictable
  • Realtime

App server Architecture

Archi

Interactive graph

Graph

Tips

Deferred execution

  • HotChocolate is designed to work seamlessly with IQueryable and supports deferred execution out of the box.
    • When you return an IQueryable from a resolver, HotChocolate will take care of executing the IQueryable.
    • ensure that the query is only executed once and only when needed. (abstracted away from the developer)

Resolver dependency injection

  • Create target service + inject it by resolver when needed to support multiple parallel operations
  • Pooled dbContext for faster data fetching, retrieve one DbContext instance from the pool for each invocation of a resolver. Once the resolver has finished executing, the instance will be returned to the pool.

XML Documentation

  • Out of the box, Hot Chocolate has the ability to automatically generate API documentation from your existing XML documentation comments. Example:
/// <summary>
/// The vehicle model object.
/// </summary>
public class Vehicle
{
    /// <summary>
    /// The unique identifier.
    /// </summary>
    public required int Id { get; init; }

    /// <summary>
    /// The country ISO code ALPHA-2.
    /// </summary>
    public string? CountryIsoCodeAlpha2 { get; init; }
}
  • you will need to enable documentation file generation for your .csproj through:
<PropertyGroup>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

Local installation

  • run dotnet ef database update to run db migrations.
  • play with the API through banana cake pop: http://localhost:5033/graphql/.
  • run the graph voyager through http://localhost:5033/ui/voyager.

Resources

Languages