Repository navigation
Expand file tree
/
Copy pathDemoQuery.cs
More file actions
54 lines (53 loc) · 3.02 KB
/
Copy pathDemoQuery.cs
File metadata and controls
54 lines (53 loc) · 3.02 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Demo.Server.Core.GraphQl.Types;
using Demo.Server.Core.Service.Interface;
using GraphQL.Types;
namespace Demo.Server.Core.GraphQl.Schema
{
public class DemoQuery : ObjectGraphType<object>
{
public DemoQuery(ITransactionService transactionService, IClientService clientService)
{
Name = "Query";
Field<ListGraphType<TransactionType>>(
"transactions",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "year" }),
resolve: context => transactionService.GetTransactions(context.GetArgument<int>("year")),
description: "Get all transactions for the specified year"
);
Field<ListGraphType<ClientType>>(
"clients",
resolve: _ => clientService.GetClients(),
description: "Get all available clients"
);
Field<ListGraphType<ClientType>>(
"client",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "id" }),
resolve: context => clientService.GetClient(context.GetArgument<int>("id")),
description: "Get client with specified ID"
);
Field<ListGraphType<ClientTransactionSummaryDtoType>>(
"topPerformingClient",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "count" }, new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "year" }),
resolve: context => clientService.GetTopPerformingClients(context.GetArgument<int>("count"), context.GetArgument<int>("year")),
description: "Get top performing clients. Max limit count = 5"
);
Field<ListGraphType<ClientTransactionSummaryDtoType>>(
"worstPerformingClient",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "count" }, new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "year" }),
resolve: context => clientService.GetWorstPerformingClients(context.GetArgument<int>("count"), context.GetArgument<int>("year")),
description: "Get worst performing clients. Max limit count = 5"
);
Field<ListGraphType<IntGraphType>>(
"availableTransactionYears",
resolve: context => transactionService.GetAvailableTransactionYears(),
description: "Get the list of years where transactions happened"
);
Field<ListGraphType<TransactionSummaryByMonthType>>(
"transactionSummaryByMonth",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IntGraphType>> { Name = "year" }),
resolve: context => transactionService.GetTransactionSummaryByMonth(context.GetArgument<int>("year")),
description: "Get transaction summary for a year by month"
);
}
}
}