Last active
October 10, 2017 13:22
-
-
Save mczachurski/4b1d0841229872022a4cf1faffe0698d 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 : IBranchesResolver | |
{ | |
private readonly IBranchesService _branchesService; | |
public BranchesResolver(IBranchesService branchesService) | |
{ | |
_branchesService = branchesService; | |
} | |
public void Resolve(GraphQLQuery graphQLQuery) | |
{ | |
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 new Response("NotFound", "Resource not found"); | |
} | |
return new Response(branch); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment