Skip to content

Commit 51e77c1

Browse files
authored
Add SDLSorter (#327)
1 parent 1e0455d commit 51e77c1

10 files changed

+533
-2
lines changed

src/GraphQLParser.ApiTests/GraphQLParser.approved.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ namespace GraphQLParser.Visitors
762762
protected virtual System.Threading.Tasks.ValueTask VisitArgumentsAsync(GraphQLParser.AST.GraphQLArguments arguments, TContext context) { }
763763
protected virtual System.Threading.Tasks.ValueTask VisitArgumentsDefinitionAsync(GraphQLParser.AST.GraphQLArgumentsDefinition argumentsDefinition, TContext context) { }
764764
public virtual System.Threading.Tasks.ValueTask VisitAsync(GraphQLParser.AST.ASTNode? node, TContext context) { }
765-
protected System.Threading.Tasks.ValueTask VisitAsync<T>(System.Collections.Generic.List<T>? nodes, TContext context)
765+
protected virtual System.Threading.Tasks.ValueTask VisitAsync<T>(System.Collections.Generic.List<T>? nodes, TContext context)
766766
where T : GraphQLParser.AST.ASTNode { }
767767
protected virtual System.Threading.Tasks.ValueTask VisitBooleanValueAsync(GraphQLParser.AST.GraphQLBooleanValue booleanValue, TContext context) { }
768768
protected virtual System.Threading.Tasks.ValueTask VisitCommentAsync(GraphQLParser.AST.GraphQLComment comment, TContext context) { }
@@ -969,6 +969,21 @@ namespace GraphQLParser.Visitors
969969
protected override System.Threading.Tasks.ValueTask VisitVariableDefinitionAsync(GraphQLParser.AST.GraphQLVariableDefinition variableDefinition, TContext context) { }
970970
protected override System.Threading.Tasks.ValueTask VisitVariablesDefinitionAsync(GraphQLParser.AST.GraphQLVariablesDefinition variablesDefinition, TContext context) { }
971971
}
972+
public sealed class SDLSorter : GraphQLParser.Visitors.ASTVisitor<GraphQLParser.Visitors.SDLSorterOptions>
973+
{
974+
protected override System.Threading.Tasks.ValueTask VisitAsync<T>(System.Collections.Generic.List<T>? nodes, GraphQLParser.Visitors.SDLSorterOptions context)
975+
where T : GraphQLParser.AST.ASTNode { }
976+
protected override System.Threading.Tasks.ValueTask VisitDirectiveLocationsAsync(GraphQLParser.AST.GraphQLDirectiveLocations directiveLocations, GraphQLParser.Visitors.SDLSorterOptions context) { }
977+
public static void Sort(GraphQLParser.AST.ASTNode node, GraphQLParser.Visitors.SDLSorterOptions? options = null) { }
978+
}
979+
public class SDLSorterOptions : GraphQLParser.Visitors.IASTVisitorContext, System.Collections.Generic.IComparer<GraphQLParser.AST.ASTNode>, System.Collections.Generic.IComparer<GraphQLParser.AST.DirectiveLocation>
980+
{
981+
public SDLSorterOptions(System.StringComparison stringComparison) { }
982+
public System.StringComparison StringComparison { get; }
983+
public static GraphQLParser.Visitors.SDLSorterOptions Default { get; }
984+
public virtual int Compare(GraphQLParser.AST.ASTNode x, GraphQLParser.AST.ASTNode y) { }
985+
public int Compare(GraphQLParser.AST.DirectiveLocation x, GraphQLParser.AST.DirectiveLocation y) { }
986+
}
972987
public class StructurePrinter : GraphQLParser.Visitors.StructurePrinter<GraphQLParser.Visitors.SDLPrinter.DefaultPrintContext>
973988
{
974989
public StructurePrinter() { }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
scalar Type3
2+
3+
schema {
4+
mutation: Type2
5+
query: Type3
6+
subscription: Type1
7+
}
8+
9+
type Type1 @dir3 @dir1 @dir2 {
10+
f1(arg3: [ID], arg1: Float, arg2: Int!): String
11+
f3: ID
12+
f2: Float
13+
}
14+
15+
# Type2 comment
16+
"Type2 description"
17+
input Type2 {
18+
"f1 description"
19+
f1: String
20+
"f3 description"
21+
f3: ID!
22+
"f2 description"
23+
f2: [[Float!]!]!
24+
}
25+
26+
directive @zdir3(arg3: [ID], arg1: Float, arg2: Int!)
27+
on FRAGMENT_SPREAD | FIELD | INLINE_FRAGMENT
28+
29+
directive @zdir1 on FIELD
30+
31+
directive @zdir2 on INLINE_FRAGMENT
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
mutation m2 {
2+
field
3+
}
4+
5+
# comments for q2
6+
query q2 {
7+
dummy
8+
}
9+
10+
subscription s3 @dir3 @dir1 @dir2 {
11+
dummy
12+
}
13+
14+
mutation m1 {
15+
field
16+
}
17+
18+
subscription s1 {
19+
dummy
20+
}
21+
22+
# l2 - comments on default query line 1
23+
# l1 - comments on default query line 2
24+
# l3 - comments on default query line 3
25+
{
26+
...fragment8
27+
field2
28+
... on Type2 {
29+
field5
30+
}
31+
...fragment7
32+
field1 (arg2: "value1", arg1: [3, 1, 2], arg3: { sub2: 1, sub1: 2, sub3: 3 })
33+
... {
34+
field4
35+
}
36+
field3 @dir2 @dir1(arg2: "value1", arg1: [3, 1, 2], arg3: { sub2: 1, sub1: 2, sub3: 3 }) @dir3
37+
...fragment9
38+
... on Type3 {
39+
field6
40+
}
41+
}
42+
43+
fragment frag2 on Type1 {
44+
dummy
45+
}
46+
47+
fragment frag1 on Type2 {
48+
dummy
49+
}
50+
51+
mutation m3 {
52+
field
53+
}
54+
55+
fragment frag3 on Type3 {
56+
dummy3
57+
dummy1
58+
dummy2
59+
}
60+
61+
subscription s2 {
62+
dummy
63+
}
64+
65+
# comments for q3
66+
query q3 ($arg2: ID, $arg1: String, $arg3: Float) {
67+
dummy
68+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
schema {
2+
query: Type3
3+
mutation: Type2
4+
subscription: Type1
5+
}
6+
7+
directive @zdir1 on FIELD
8+
9+
directive @zdir2 on INLINE_FRAGMENT
10+
11+
directive @zdir3(arg1: Float, arg2: Int!, arg3: [ID]) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
12+
13+
type Type1 @dir1 @dir2 @dir3 {
14+
f1(arg1: Float, arg2: Int!, arg3: [ID]): String
15+
f2: Float
16+
f3: ID
17+
}
18+
19+
# Type2 comment
20+
"Type2 description"
21+
input Type2 {
22+
23+
"f1 description"
24+
f1: String
25+
26+
"f2 description"
27+
f2: [[Float!]!]!
28+
29+
"f3 description"
30+
f3: ID!
31+
}
32+
33+
scalar Type3
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# l2 - comments on default query line 1
2+
# l1 - comments on default query line 2
3+
# l3 - comments on default query line 3
4+
{
5+
field1(arg1: [3, 1, 2], arg2: "value1", arg3: {sub1: 2, sub2: 1, sub3: 3})
6+
field2
7+
field3 @dir1(arg1: [3, 1, 2], arg2: "value1", arg3: {sub1: 2, sub2: 1, sub3: 3}) @dir2 @dir3
8+
... {
9+
field4
10+
}
11+
... on Type2 {
12+
field5
13+
}
14+
... on Type3 {
15+
field6
16+
}
17+
...fragment7
18+
...fragment8
19+
...fragment9
20+
}
21+
22+
# comments for q2
23+
query q2 {
24+
dummy
25+
}
26+
27+
# comments for q3
28+
query q3($arg1: String, $arg2: ID, $arg3: Float) {
29+
dummy
30+
}
31+
32+
mutation m1 {
33+
field
34+
}
35+
36+
mutation m2 {
37+
field
38+
}
39+
40+
mutation m3 {
41+
field
42+
}
43+
44+
subscription s1 {
45+
dummy
46+
}
47+
48+
subscription s2 {
49+
dummy
50+
}
51+
52+
subscription s3 @dir1 @dir2 @dir3 {
53+
dummy
54+
}
55+
56+
fragment frag2 on Type1 {
57+
dummy
58+
}
59+
60+
fragment frag1 on Type2 {
61+
dummy
62+
}
63+
64+
fragment frag3 on Type3 {
65+
dummy1
66+
dummy2
67+
dummy3
68+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
query
3+
unnamed(falsey: false, truthy: true)
4+
}
5+
6+
# Copyright (c) 2015, Facebook, Inc.
7+
# All rights reserved.
8+
#
9+
# This source code is licensed under the BSD-style license found in the
10+
# LICENSE file in the root directory of this source tree. An additional grant
11+
# of patent rights can be found in the PATENTS file in the same directory.
12+
query queryName($foo: ComplexType, $site: Site = MOBILE) {
13+
whoever123is: node(id: [123, 456]) {
14+
id
15+
... @skip(unless: $foo) {
16+
id
17+
}
18+
... {
19+
id
20+
}
21+
... on User @defer {
22+
field2 {
23+
alias: field1(after: $foo, first: 10) @include(if: $foo) {
24+
id
25+
...frag
26+
}
27+
id
28+
}
29+
}
30+
}
31+
}
32+
33+
mutation likeStory {
34+
like(story: 123) @defer {
35+
story {
36+
id
37+
}
38+
}
39+
}
40+
41+
mutation updateStory {
42+
like(story: {EndDate: null, id: 123}) {
43+
story {
44+
id
45+
}
46+
}
47+
}
48+
49+
subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
50+
storyLikeSubscribe(input: $input) {
51+
story {
52+
likers {
53+
count
54+
}
55+
likeSentence {
56+
text
57+
}
58+
}
59+
}
60+
}
61+
62+
fragment frag on Friend {
63+
foo(bar: $b, obj: {key: "value"}, size: $size)
64+
}
65+
66+
# Copyright (c) 2015, Facebook, Inc.
67+
# All rights reserved.
68+
#
69+
# This source code is licensed under the BSD-style license found in the
70+
# LICENSE file in the root directory of this source tree. An additional grant
71+
# of patent rights can be found in the PATENTS file in the same directory.
72+
schema {
73+
query: QueryType
74+
mutation: MutationType
75+
}
76+
77+
directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
78+
79+
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT
80+
81+
enum AnnotatedEnum @onEnum {
82+
ANNOTATED_VALUE @onEnumValue
83+
OTHER_VALUE
84+
}
85+
86+
input AnnotatedInput @onInputObjectType {
87+
annotatedField: Type @onField
88+
}
89+
90+
interface AnnotatedInterface @onInterface {
91+
annotatedField(arg: Type @onArg): Type @onField
92+
}
93+
94+
type AnnotatedObject @onObject(arg: "value") {
95+
# a comment
96+
annotatedField(arg: Type = "default" @onArg): Type @onField
97+
}
98+
99+
scalar AnnotatedScalar @onScalar
100+
101+
union AnnotatedUnion @onUnion = A | B
102+
103+
interface Bar {
104+
four(argument: String = "string"): String
105+
one: Type
106+
}
107+
108+
scalar CustomScalar
109+
110+
union Feed = Advert | Article | Story
111+
112+
type Foo implements Bar {
113+
five(argument: [String] = ["string", "string"]): String
114+
four(argument: String = "string"): String
115+
# comment 1
116+
one: Type
117+
six(argument: InputType = {key: "value"}): Type
118+
# multiline comments
119+
# with very important description #
120+
# # and symbol # and ##
121+
three(argument: InputType, other: String): Int
122+
# comment 2
123+
two(argument: InputType!): Type
124+
}
125+
126+
input InputType {
127+
answer: Int = 42
128+
key: String!
129+
}
130+
131+
type NoFields
132+
133+
enum Site {
134+
DESKTOP
135+
MOBILE
136+
}
137+
138+
extend type Foo {
139+
seven(argument: [String]): Type
140+
}
141+
142+
extend type Foo @onType

0 commit comments

Comments
 (0)