-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathQuerybuilderHelper.cs
More file actions
58 lines (49 loc) · 1.66 KB
/
QuerybuilderHelper.cs
File metadata and controls
58 lines (49 loc) · 1.66 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
55
56
57
58
using System.Collections.Generic;
using GraphQL.Language.AST;
using System.Linq;
using GraphQL;
namespace Dapper.GraphQL.Test.QueryBuilders
{
public static class QueryBuilderHelper
{
public static Dictionary<string, Field> CollectFields(SelectionSet selectionSet)
{
return CollectFields(selectionSet, Fields.Empty());
}
private static Fields CollectFields(SelectionSet selectionSet, Fields fields)
{
List<string> skipList = new List<string> { "edges", "node", "cursor" };
selectionSet?.Selections.Apply(selection =>
{
if (selection is Field field)
{
if (!skipList.Exists(name => name.ToLower().Equals(field.Name)))
{
fields.Add(field);
}
CollectFields(field.SelectionSet, fields);
}
});
return fields;
}
public static bool IsConnection(SelectionSet selectionSet)
{
return IsConnection(selectionSet, new Dictionary<string, Field>());
}
public static bool IsConnection(SelectionSet selectionSet, Dictionary<string, Field> fields)
{
selectionSet?.Selections.Apply(selection =>
{
if (selection is Field field)
{
if (field.Name == "edges")
{
fields.Add(field.Name, field);
}
IsConnection(field.SelectionSet, fields);
}
});
return fields.Any();
}
}
}