Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Last active October 10, 2017 13:22
Show Gist options
  • Save mczachurski/294f8c6244227258fccf02cc6fe18d38 to your computer and use it in GitHub Desktop.
Save mczachurski/294f8c6244227258fccf02cc6fe18d38 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<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