This file contains hidden or 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
[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; |
This file contains hidden or 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 GraphQLSchema : Schema | |
{ | |
public GraphQLSchema(Func<Type, GraphType> resolveType) | |
: base(resolveType) | |
{ | |
Query = (GraphQLQuery)resolveType(typeof(GraphQLQuery)); | |
} | |
} |
This file contains hidden or 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
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; | |
}; | |
}); |
This file contains hidden or 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
builder.RegisterType<DocumentExecuter>().As<IDocumentExecuter>(); |
This file contains hidden or 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 GraphQLQuery : ObjectGraphType | |
{ | |
public GraphQLQuery(IServiceProvider serviceProvider) | |
{ | |
var type = typeof(IResolver); | |
var resolversTypes = AppDomain.CurrentDomain.GetAssemblies() | |
.SelectMany(s => s.GetTypes()) | |
.Where(p => type.IsAssignableFrom(p)); | |
foreach(var resolverType in resolversTypes) |
This file contains hidden or 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 interface IResolver | |
{ | |
void Resolve(GraphQLQuery graphQLQuery); | |
} |
This file contains hidden or 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 GroupsResolver : Resolver, IGroupsResolver | |
{ | |
private readonly IGroupsService _groupsService; | |
public GroupsResolver(IGroupsService groupsService) | |
{ | |
_groupsService = groupsService; | |
} | |
public void Resolve(GraphQLQuery graphQLQuery) |
This file contains hidden or 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
var serviceAssembly = typeof(IResolver).GetTypeInfo().Assembly; | |
builder.RegisterAssemblyTypes(serviceAssembly) | |
.Where(t => t.Name.EndsWith("Resolver")) | |
.AsImplementedInterfaces() | |
.InstancePerLifetimeScope(); |
This file contains hidden or 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 GroupType : ObjectGraphType<GroupDto>, IGraphQLType | |
{ | |
public GroupType() | |
{ | |
Field(x => x.Name).Description("The group name."); | |
Field(x => x.SvgIcon).Description("The icon of group."); | |
} | |
} |
This file contains hidden or 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 GroupDto | |
{ | |
public string Name { get; set; } | |
public string SvgIcon { get; set; } | |
} |