-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathResolveDbContextQuery.cs
More file actions
36 lines (30 loc) · 973 Bytes
/
ResolveDbContextQuery.cs
File metadata and controls
36 lines (30 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using GraphQL.Types;
class ResolveDbContextQuery
{
#region QueryResolveDbContext
public class Query :
QueryGraphType<MyDbContext>
{
public Query(IEfGraphQLService<MyDbContext> graphQlService) :
base(graphQlService) =>
Field<ListGraphType<CompanyGraph>>("oldCompanies")
.Resolve(context =>
{
// uses the base QueryGraphType to resolve the db context
var data = ResolveDbContext(context);
return data.Companies.Where(_ => _.Age > 10);
});
}
#endregion
public class MyDbContext :
DbContext
{
public IQueryable<Company> Companies { get; set; } = null!;
}
public class Company
{
public int Age { get; set; }
}
class CompanyGraph(IEfGraphQLService<MyDbContext> efGraphQlService) :
EfObjectGraphType<MyDbContext, Company>(efGraphQlService);
}