/
StarWarsQuery.cs
37 lines (32 loc) · 1.27 KB
/
StarWarsQuery.cs
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
using System;
using GraphQL;
using GraphQL.Types;
using StarWars.API.Security;
using StarWars.API.Services;
namespace StarWars.API.Schema
{
public class StarWarsQuery : ObjectGraphType
{
public StarWarsQuery(IStarWarsDataService data)
{
Name = "Query";
Field<CharacterInterface>("hero", resolve: context => data.GetDroidByIdAsync("3"))
.AuthorizeWith(Policies.CharacterAccess);
Field<HumanType>(
"human",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "id", Description = "id of the human" }
),
resolve: context => data.GetHumanByIdAsync(context.GetArgument<string>("id"))
).AuthorizeWith(Policies.CharacterAccess);
Func<IResolveFieldContext, string, object> func = (context, id) => data.GetDroidByIdAsync(id);
FieldDelegate<DroidType>(
"droid",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<StringGraphType>> { Name = "id", Description = "id of the droid" }
),
resolve: func
).AuthorizeWith(Policies.CharacterAccess);
}
}
}