Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Created October 10, 2017 13:27
Show Gist options
  • Save mczachurski/49b7b12aee42e6aeec314e4e621c9b0c to your computer and use it in GitHub Desktop.
Save mczachurski/49b7b12aee42e6aeec314e4e621c9b0c to your computer and use it in GitHub Desktop.
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