Skip to content

Instantly share code, notes, and snippets.

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