-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathDefaultQueryArguments.cs
62 lines (54 loc) · 1.95 KB
/
DefaultQueryArguments.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using GraphQL.Types;
namespace Graphql.Extensions.FieldEnums.Types
{
public static class DefaultQueryArguments
{
public static IEnumerable<QueryArgument> SkipTakeOrderByArguments<TTargetType>()
=> SkipTakeOrderByArguments(typeof(TTargetType));
public static IEnumerable<QueryArgument> SkipTakeOrderByArguments(Type targetType)
{
yield return Skip;
yield return Take;
yield return GetOrderBy(targetType);
yield return GetOrderByDesc(targetType);
}
public static QueryArgument Skip => new QueryArgument(typeof(IntGraphType))
{
Name = "skip",
Description = "skip n entries",
};
public static QueryArgument Take => new QueryArgument(typeof(IntGraphType))
{
Name = "take",
Description = "take n entries",
};
public static QueryArgument GetOrderBy(Type type)
{
var typedArg = type;
if (type.IsGenericType == false || type.GetGenericTypeDefinition() != typeof(TypeFieldEnumerationWithoutLists<>))
{
typedArg = typeof(TypeFieldEnumerationWithoutLists<>).MakeGenericType(type);
}
return new QueryArgument(typedArg)
{
Name = "orderBy",
Description = "order by",
};
}
public static QueryArgument GetOrderByDesc(Type type)
{
var typedArg = type;
if (type.IsGenericType == false || type.GetGenericTypeDefinition() != typeof(TypeFieldEnumerationWithoutLists<>))
{
typedArg = typeof(TypeFieldEnumerationWithoutLists<>).MakeGenericType(type);
}
return new QueryArgument(typedArg)
{
Name = "orderByDesc",
Description = "order by desc",
};
}
}
}