public CharacterQlQuery(MsSql1DbContext db) { Field <CharacterQl>( "Character", arguments: new QueryArguments( new QueryArgument <IdGraphType> { Name = "id", Description = "The ID of the Character." }), resolve: context => { var id = context.GetArgument <int>("id"); var character = db .Character .Include(a => a.User) .FirstOrDefault(i => i.Id == id); return(character); }); Field <ListGraphType <CharacterQl> >( "Characters", resolve: context => { var character = db.Character.Include(a => a.User); return(character); }); }
public TestPagingQuery(MsSql1DbContext db) { Name = "TestPaging"; Field <PageInfoType>( "paginatedCompany", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "page", Description = "page of the list" }, new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "size", Description = "size of the list returned" }, new QueryArgument <StringGraphType> { Name = "q", Description = "filter by name" } ), resolve: context => { var result = GetGenericUsersAsync(db, context.GetArgument <int>("page"), context.GetArgument <int>("size"), context.GetArgument <string>("q")); return(result); } ); }
public GraphQLController(MsSql1DbContext db) { _db = db; entityTypes = _db.Model.GetEntityTypes().Select(s => s.Name.Split(".").LastOrDefault()).ToList(); QlQueries = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) .Where(x => x.Name.EndsWith("QlQuery") && typeof(ObjectGraphType).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract) .Select(x => new QlQueryName { FullName = x.FullName, Name = x.Name }).ToList(); }
public Task <PageInfo <GenericUser> > GetGenericUsersAsync(MsSql1DbContext db, int page, int size, string q = "") { IEnumerable <GenericUser> filtered; //if (!string.IsNullOrEmpty(q)) //{ // filtered = db.Users.Where(xx => xx..ToUpper().Contains(q.ToUpper())); //} //else //{ // filtered = _companies; //} PageInfo <GenericUser> comp = new PageInfo <GenericUser>(db.Users, page, size); // comp.Chars = filtered.Select(xx => xx.user.ToUpper().Remove(1)).OrderBy(xx => xx).Distinct(); return(Task.FromResult(comp)); }
public GenericUserQlQuery(MsSql1DbContext db) { Field <GenericUserQl>( "GenericUser", arguments: new QueryArguments( new QueryArgument <IdGraphType> { Name = "id", Description = "The ID of the User." }, new QueryArgument <IdGraphType> { Name = "firstName", Description = "The FirstName of the User." } ), resolve: context => { var id = context.GetArgument <int>("id"); var firstName = context.GetArgument <string>("firstName"); var user = db.User.Include(a => a.Character).FirstOrDefault(); return(user); }); Field <ListGraphType <GenericUserQl> >( "GenericUsers", arguments: new QueryArguments( new QueryArgument <IdGraphType> { Name = "firstName", Description = "The FirstName of the User." } ), resolve: context => { var firstName = context.GetArgument <string>("firstName"); var users = db.User.Where(w => w.FirstName == firstName).Include(a => a.Character); return(users); }); }