-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
SortVisitorBase`2.cs
113 lines (95 loc) · 3.05 KB
/
SortVisitorBase`2.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using HotChocolate.Language;
using HotChocolate.Language.Visitors;
namespace HotChocolate.Data.Sorting
{
public abstract class SortVisitorBase<TContext, T>
: SortVisitorBase<TContext>
where TContext : SortVisitorContext<T>
{
protected SortVisitorBase()
{
}
protected abstract ISyntaxVisitorAction OnFieldEnter(
TContext context,
ISortField field,
ObjectFieldNode node);
protected abstract ISyntaxVisitorAction OnFieldLeave(
TContext context,
ISortField field,
ObjectFieldNode node);
protected abstract ISyntaxVisitorAction OnOperationEnter(
TContext context,
ISortField field,
ISortEnumValue? sortEnumValue,
EnumValueNode enumValueNode);
protected override ISyntaxVisitorAction Enter(
ObjectFieldNode node,
TContext context)
{
base.Enter(node, context);
if (context.Fields.Peek() is ISortField field)
{
return OnFieldEnter(context, field, node);
}
return Continue;
}
protected override ISyntaxVisitorAction Enter(IValueNode node, TContext context)
{
base.Enter(node, context);
if (context.Fields.Peek() is ISortField field &&
field.Type is SortEnumType sortType &&
node is EnumValueNode enumValueNode)
{
return OnOperationEnter(
context,
field,
sortType.ParseSortLiteral(node),
enumValueNode);
}
return Continue;
}
protected override ISyntaxVisitorAction Leave(
ObjectFieldNode node,
TContext context)
{
ISyntaxVisitorAction result = Continue;
if (context.Fields.Peek() is ISortField field)
{
result = OnFieldLeave(context, field, node);
}
base.Leave(node, context);
return result;
}
protected override ISyntaxVisitorAction Enter(
ListValueNode node,
TContext context)
{
if (context.Fields.Count > 0 &&
context.Fields.Peek() is ISortField sortField)
{
context.ReportError(ErrorHelper.SortingVisitor_ListValues(sortField, node));
}
else
{
return Continue;
}
return Break;
}
protected override ISyntaxVisitorAction Leave(
ListValueNode node,
TContext context)
{
if (context.Fields.Count > 0 &&
context.Fields.Peek() is ISortField sortField)
{
context.ReportError(ErrorHelper.SortingVisitor_ListValues(sortField, node));
}
else
{
return Continue;
}
return Break;
}
}
}