An open API service indexing awesome lists of open source software.

https://github.com/michaelhilus/nitrolize

Semi automatic Relay compatible GraphQL for C#
https://github.com/michaelhilus/nitrolize

csharp dotnet-core graphql graphql-server graphql-server-framework semi-automatic

Last synced: 2 months ago
JSON representation

Semi automatic Relay compatible GraphQL for C#

Awesome Lists containing this project

README

        

![Logo](static/nitrolize-github-logo-background.png "Logo")
Nitrolize accelerates your GraphQL server development in C#.

Based on [GraphQL for .NET](http://github.com/graphql-dotnet/graphql-dotnet) it offers
* mechanisms to auto generate Relay compatible GraphQL Types from your domain model classes,
* auto converts Guid / int Ids from your domain model to Base64 encoded unique ids for your client and vice versa,
* simplifies field declaration by an easy to use syntax.

## Example usage
Your user domain model:
```csharp
public class User
{
public Guid Id { get;set; }
public string NickName { get; set; }
public string Mail { get; set; }
public int FavoriteNumber { get; set; }
}
```
Your ViewerType:
```csharp
public class ViewerType : NitrolizeViewerType
{
private readonly IUserRepository userRepository;

public ViewerType(IUserRepository userRepository)
{
this.userRepository = userRepository;
}

///
/// Gets a user by id.
///
[Field]
public Field User => (context, id) =>
{
return this.userRepository.GetUserById(id);
};

///
/// Gets all users.
///
[Connection]
public ConnectionField Users => (context, parameters) =>
{
return new Connection(this.userRepository.GetAllUsers());
};
}
```

Possible GraphQL query:
```
{
viewer {
users {
edges {
cursor
node {
id
nickName
mail
favoriteNumber
}
}
}
user(id: "VXNlciNjYWVmYjc5Mi04ODFmLTRmMjAtYmI5ZC1jNDAzMjY5OGQxMGM=") {
nickName
mail
favoriteNumber
}
}
}
```