Skip to content

Instantly share code, notes, and snippets.

View mczachurski's full-sized avatar

Marcin Czachurski mczachurski

View GitHub Profile
builder.RegisterType<DocumentExecuter>().As<IDocumentExecuter>();
builder.RegisterType<GraphQLSchema>().As<ISchema>();
builder.Register<Func<Type, GraphType>>(c =>
{
var context = c.Resolve<IComponentContext>();
return t => {
var res = context.Resolve(t);
return (GraphType)res;
};
});
public class GraphQLSchema : Schema
{
public GraphQLSchema(Func<Type, GraphType> resolveType)
: base(resolveType)
{
Query = (GraphQLQuery)resolveType(typeof(GraphQLQuery));
}
}
[Route("api/graphql")]
public class GraphQLController : Controller
{
private readonly GraphQLQuery _graphQLQuery;
private readonly IDocumentExecuter _documentExecuter;
private readonly ISchema _schema;
public GraphQLController(GraphQLQuery graphQLQuery, IDocumentExecuter documentExecuter, ISchema schema)
{
_graphQLQuery = graphQLQuery;
public class GraphQLParameter
{
public string Query { get; set; }
}
public class BranchesResolver : Resolver, IBranchesResolver
{
private readonly IBranchesService _branchesService;
public BranchesResolver(IBranchesService branchesService)
{
_branchesService = branchesService;
}
public void Resolve(GraphQLQuery graphQLQuery)
public class ResponseListGraphType<TGraphType> : ObjectGraphType<Response> where TGraphType : GraphType
{
public ResponseListGraphType()
{
Name = $"ResponseList{typeof(TGraphType).Name}";
Field(x => x.StatusCode, nullable: true).Description("Status code of the request.");
Field(x => x.ErrorMessage, nullable: true).Description("Error message if requests fails.");
Field<ListGraphType<TGraphType>>(
public class BranchesResolver : Resolver, IBranchesResolver
{
private readonly IBranchesService _branchesService;
public BranchesResolver(IBranchesService branchesService)
{
_branchesService = branchesService;
}
public void Resolve(GraphQLQuery graphQLQuery)
public class Resolver
{
public Response Response(object data)
{
return new Response(data);
}
public Response Error(GraphQLError error)
{
return new Response(error.StatusCode, error.ErrorMessage);
public class BranchesResolver : IBranchesResolver
{
private readonly IBranchesService _branchesService;
public BranchesResolver(IBranchesService branchesService)
{
_branchesService = branchesService;
}
public void Resolve(GraphQLQuery graphQLQuery)