项目作者: progresso-group

项目描述 :
Semi automatic Relay compatible GraphQL for C#
高级语言: C#
项目地址: git://github.com/progresso-group/Nitrolize.git
创建时间: 2017-03-25T22:41:01Z
项目社区:https://github.com/progresso-group/Nitrolize

开源协议:Other

下载


Logo
Nitrolize accelerates your GraphQL server development in C#.

Based on GraphQL for .NET 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:

  1. public class User
  2. {
  3. public Guid Id { get;set; }
  4. public string NickName { get; set; }
  5. public string Mail { get; set; }
  6. public int FavoriteNumber { get; set; }
  7. }

Your ViewerType:

  1. public class ViewerType : NitrolizeViewerType
  2. {
  3. private readonly IUserRepository userRepository;
  4. public ViewerType(IUserRepository userRepository)
  5. {
  6. this.userRepository = userRepository;
  7. }
  8. /// <summary>
  9. /// Gets a user by id.
  10. /// </summary>
  11. [Field]
  12. public Field<User, Guid> User => (context, id) =>
  13. {
  14. return this.userRepository.GetUserById(id);
  15. };
  16. /// <summary>
  17. /// Gets all users.
  18. /// </summary>
  19. [Connection]
  20. public ConnectionField<User> Users => (context, parameters) =>
  21. {
  22. return new Connection<User, Guid>(this.userRepository.GetAllUsers());
  23. };
  24. }

Possible GraphQL query:

  1. {
  2. viewer {
  3. users {
  4. edges {
  5. cursor
  6. node {
  7. id
  8. nickName
  9. mail
  10. favoriteNumber
  11. }
  12. }
  13. }
  14. user(id: "VXNlciNjYWVmYjc5Mi04ODFmLTRmMjAtYmI5ZC1jNDAzMjY5OGQxMGM=") {
  15. nickName
  16. mail
  17. favoriteNumber
  18. }
  19. }
  20. }