Beispiel #1
0
 public UserType(PostRepository postRepo, FollowerRepository followerRepo, UserRepository userRepo)
 {
     Name = "User";
     Field(x => x.Id, type: typeof(IdGraphType)).Description("User ID");
     Field(x => x.Name, nullable: true, type: typeof(StringGraphType)).Description("User Name");
     Field(x => x.Address, type: typeof(StringGraphType)).Description("User Address");
     Field(x => x.Birthday, type: typeof(DateTimeGraphType)).Description("User BirthDay");
     Field <ListGraphType <PostType> >(
         "posts",
         resolve: ctx =>
     {
         return(postRepo.GetPostByUserId(ctx.Source.Id));
     });
     Field <ListGraphType <FollowersType> >(
         "follower",
         resolve: ctx =>
     {
         return(followerRepo.GetPostByFollowedUserId(ctx.Source.Id));
     });
 }
Beispiel #2
0
        public ExampleQuery(UserRepository userRepo, PostRepository postRepo, FollowerRepository followerRepo, GitHubApi gitHubApi)
        {
            Name        = "Query";
            Description = "Simple query example, exposes (user, post and follower)";

            Field <ListGraphType <UserType> >(
                "users",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "offset"
            },
                    new QueryArgument <IntGraphType> {
                Name = "limit", DefaultValue = 10
            }
                    ),
                resolve: ctx =>
            {
                var offset = ctx.GetArgument <int>("offset");
                var limit  = ctx.GetArgument <int>("limit");

                //if (limit == 0)
                //{
                //    ctx.Errors.Add(new ExecutionError("The argument [limit] must be greater than 0."));
                //    return null;
                //}
                //if (limit == 0)
                //    limit = 10;

                return(userRepo.GetAllUsers(offset, limit));
            }
                );

            Field <UserType>(
                "userById",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }
                    ),
                resolve: ctx =>
            {
                var id = ctx.GetArgument <int>("id");
                return(userRepo.GetUserById(id));
            }
                );

            Field <ListGraphType <PostType> >(
                "posts",
                resolve: ctx => postRepo.GetAll()
                );

            Field <ListGraphType <FollowersType> >(
                "followers",
                resolve: ctx => followerRepo.GetAll()
                );

            //Field<ListGraphType<GitHubBranchType>>(
            //    "branches",
            //    resolve: ctx => gitHubApi.GetBranches()
            //);
        }