-
-
Notifications
You must be signed in to change notification settings - Fork 725
/
DocumentValidatorContext.cs
178 lines (144 loc) · 5.33 KB
/
DocumentValidatorContext.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System;
using System.Collections.Generic;
using HotChocolate.Language;
using HotChocolate.Types;
using HotChocolate.Validation.Properties;
namespace HotChocolate.Validation
{
public sealed class DocumentValidatorContext : IDocumentValidatorContext
{
private static readonly FieldInfoListBufferPool _fieldInfoPool =
new FieldInfoListBufferPool();
private readonly List<FieldInfoListBuffer> _buffers =
new List<FieldInfoListBuffer>
{
new FieldInfoListBuffer()
};
private ISchema? _schema;
private IOutputType? _nonNullString;
private bool _unexpectedErrorsDetected;
public ISchema Schema
{
get
{
if (_schema is null)
{
// TODO : resources
throw new InvalidOperationException(
Resources.DocumentValidatorContext_Context_Invalid_State);
}
return _schema;
}
set
{
_schema = value;
NonNullString = new NonNullType(_schema.GetType<StringType>("String"));
}
}
public IOutputType NonNullString
{
get
{
if (_nonNullString is null)
{
// TODO : resources
throw new InvalidOperationException(
Resources.DocumentValidatorContext_Context_Invalid_State);
}
return _nonNullString;
}
private set => _nonNullString = value;
}
public IList<ISyntaxNode> Path { get; } = new List<ISyntaxNode>();
public IList<SelectionSetNode> SelectionSets { get; } = new List<SelectionSetNode>();
public IDictionary<SelectionSetNode, IList<FieldInfo>> FieldSets { get; } =
new Dictionary<SelectionSetNode, IList<FieldInfo>>();
public ISet<(FieldNode, FieldNode)> FieldTuples { get; } =
new HashSet<(FieldNode, FieldNode)>();
public ISet<string> VisitedFragments { get; } = new HashSet<string>();
public IDictionary<string, object> VariableValues { get; } =
new Dictionary<string, object>();
public IDictionary<string, VariableDefinitionNode> Variables { get; } =
new Dictionary<string, VariableDefinitionNode>();
public IDictionary<string, FragmentDefinitionNode> Fragments { get; } =
new Dictionary<string, FragmentDefinitionNode>();
public ISet<string> Used { get; } = new HashSet<string>();
public ISet<string> Unused { get; } = new HashSet<string>();
public ISet<string> Declared { get; } = new HashSet<string>();
public ISet<string> Names { get; } = new HashSet<string>();
public IList<IType> Types { get; } = new List<IType>();
public IList<DirectiveType> Directives { get; } = new List<DirectiveType>();
public IList<IOutputField> OutputFields { get; } = new List<IOutputField>();
public IList<FieldNode> Fields { get; } = new List<FieldNode>();
public IList<IInputField> InputFields { get; } = new List<IInputField>();
public ICollection<IError> Errors { get; } = new List<IError>();
public bool UnexpectedErrorsDetected
{
get => _unexpectedErrorsDetected;
set
{
_unexpectedErrorsDetected = value;
}
}
public int Count { get; set; }
public int Max { get; set; }
public IDictionary<string, object> ContextData { get; } = new Dictionary<string, object>();
public IList<FieldInfo> RentFieldInfoList()
{
FieldInfoListBuffer buffer = _buffers.Peek();
if (!buffer.TryPop(out IList<FieldInfo>? list))
{
buffer = _fieldInfoPool.Get();
_buffers.Push(buffer);
list = buffer.Pop();
}
return list;
}
public void Clear()
{
ClearBuffers();
_schema = null;
_nonNullString = null;
Path.Clear();
SelectionSets.Clear();
FieldSets.Clear();
FieldTuples.Clear();
VisitedFragments.Clear();
VariableValues.Clear();
Variables.Clear();
Fragments.Clear();
Used.Clear();
Unused.Clear();
Declared.Clear();
Names.Clear();
Types.Clear();
Directives.Clear();
OutputFields.Clear();
Fields.Clear();
InputFields.Clear();
Errors.Clear();
UnexpectedErrorsDetected = false;
Count = 0;
Max = 0;
ContextData.Clear();
}
private void ClearBuffers()
{
if (_buffers.Count > 1)
{
FieldInfoListBuffer buffer = _buffers.Pop();
buffer.Clear();
for (int i = 0; i < _buffers.Count; i++)
{
_fieldInfoPool.Return(_buffers[i]);
}
_buffers.Clear();
_buffers.Add(buffer);
}
else
{
_buffers[0].Clear();
}
}
}
}