Created
October 10, 2017 13:27
-
-
Save mczachurski/49b7b12aee42e6aeec314e4e621c9b0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BranchesResolver : Resolver, IBranchesResolver | |
{ | |
private readonly IBranchesService _branchesService; | |
public BranchesResolver(IBranchesService branchesService) | |
{ | |
_branchesService = branchesService; | |
} | |
public void Resolve(GraphQLQuery graphQLQuery) | |
{ | |
graphQLQuery.Field<ResponseListGraphType<BranchType>>( | |
"branches", | |
arguments: new QueryArguments( | |
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "projectId", Description = "id of the project" } | |
), | |
resolve: context => { | |
var projectId = context.GetArgument<string>("projectId"); | |
var list = _branchesService.GetBranchesAsync(projectId).GetAwaiter().GetResult(); | |
return Response(list); | |
} | |
); | |
graphQLQuery.Field<ResponseGraphType<BranchType>>( | |
"branch", | |
arguments: new QueryArguments( | |
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "projectId", Description = "id of the project" }, | |
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "branchName", Description = "name of the branch" } | |
), | |
resolve: context => { | |
var projectId = context.GetArgument<string>("projectId"); | |
var branchName = context.GetArgument<string>("branchName"); | |
var branch = _branchesService.GetBranchAsync(projectId, branchName).GetAwaiter().GetResult(); | |
if(branch == null) | |
{ | |
return NotFoundError(branchName); | |
} | |
return Response(branch); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment