Skip to content

Add SDLSorter #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/GraphQLParser.ApiTests/GraphQLParser.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ namespace GraphQLParser.Visitors
protected virtual System.Threading.Tasks.ValueTask VisitArgumentsAsync(GraphQLParser.AST.GraphQLArguments arguments, TContext context) { }
protected virtual System.Threading.Tasks.ValueTask VisitArgumentsDefinitionAsync(GraphQLParser.AST.GraphQLArgumentsDefinition argumentsDefinition, TContext context) { }
public virtual System.Threading.Tasks.ValueTask VisitAsync(GraphQLParser.AST.ASTNode? node, TContext context) { }
protected System.Threading.Tasks.ValueTask VisitAsync<T>(System.Collections.Generic.List<T>? nodes, TContext context)
protected virtual System.Threading.Tasks.ValueTask VisitAsync<T>(System.Collections.Generic.List<T>? nodes, TContext context)
where T : GraphQLParser.AST.ASTNode { }
protected virtual System.Threading.Tasks.ValueTask VisitBooleanValueAsync(GraphQLParser.AST.GraphQLBooleanValue booleanValue, TContext context) { }
protected virtual System.Threading.Tasks.ValueTask VisitCommentAsync(GraphQLParser.AST.GraphQLComment comment, TContext context) { }
Expand Down Expand Up @@ -969,6 +969,21 @@ namespace GraphQLParser.Visitors
protected override System.Threading.Tasks.ValueTask VisitVariableDefinitionAsync(GraphQLParser.AST.GraphQLVariableDefinition variableDefinition, TContext context) { }
protected override System.Threading.Tasks.ValueTask VisitVariablesDefinitionAsync(GraphQLParser.AST.GraphQLVariablesDefinition variablesDefinition, TContext context) { }
}
public sealed class SDLSorter : GraphQLParser.Visitors.ASTVisitor<GraphQLParser.Visitors.SDLSorterOptions>
{
protected override System.Threading.Tasks.ValueTask VisitAsync<T>(System.Collections.Generic.List<T>? nodes, GraphQLParser.Visitors.SDLSorterOptions context)
where T : GraphQLParser.AST.ASTNode { }
protected override System.Threading.Tasks.ValueTask VisitDirectiveLocationsAsync(GraphQLParser.AST.GraphQLDirectiveLocations directiveLocations, GraphQLParser.Visitors.SDLSorterOptions context) { }
public static void Sort(GraphQLParser.AST.ASTNode node, GraphQLParser.Visitors.SDLSorterOptions? options = null) { }
}
public class SDLSorterOptions : GraphQLParser.Visitors.IASTVisitorContext, System.Collections.Generic.IComparer<GraphQLParser.AST.ASTNode>, System.Collections.Generic.IComparer<GraphQLParser.AST.DirectiveLocation>
{
public SDLSorterOptions(System.StringComparison stringComparison) { }
public System.StringComparison StringComparison { get; }
public static GraphQLParser.Visitors.SDLSorterOptions Default { get; }
public virtual int Compare(GraphQLParser.AST.ASTNode x, GraphQLParser.AST.ASTNode y) { }
public int Compare(GraphQLParser.AST.DirectiveLocation x, GraphQLParser.AST.DirectiveLocation y) { }
}
public class StructurePrinter : GraphQLParser.Visitors.StructurePrinter<GraphQLParser.Visitors.SDLPrinter.DefaultPrintContext>
{
public StructurePrinter() { }
Expand Down
31 changes: 31 additions & 0 deletions src/GraphQLParser.Tests/Files/DefinitionSortTests.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
scalar Type3

schema {
mutation: Type2
query: Type3
subscription: Type1
}

type Type1 @dir3 @dir1 @dir2 {
f1(arg3: [ID], arg1: Float, arg2: Int!): String
f3: ID
f2: Float
}

# Type2 comment
"Type2 description"
input Type2 {
"f1 description"
f1: String
"f3 description"
f3: ID!
"f2 description"
f2: [[Float!]!]!
}

directive @zdir3(arg3: [ID], arg1: Float, arg2: Int!)
on FRAGMENT_SPREAD | FIELD | INLINE_FRAGMENT

directive @zdir1 on FIELD

directive @zdir2 on INLINE_FRAGMENT
68 changes: 68 additions & 0 deletions src/GraphQLParser.Tests/Files/ExecutableSortTests.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
mutation m2 {
field
}

# comments for q2
query q2 {
dummy
}

subscription s3 @dir3 @dir1 @dir2 {
dummy
}

mutation m1 {
field
}

subscription s1 {
dummy
}

# l2 - comments on default query line 1
# l1 - comments on default query line 2
# l3 - comments on default query line 3
{
...fragment8
field2
... on Type2 {
field5
}
...fragment7
field1 (arg2: "value1", arg1: [3, 1, 2], arg3: { sub2: 1, sub1: 2, sub3: 3 })
... {
field4
}
field3 @dir2 @dir1(arg2: "value1", arg1: [3, 1, 2], arg3: { sub2: 1, sub1: 2, sub3: 3 }) @dir3
...fragment9
... on Type3 {
field6
}
}

fragment frag2 on Type1 {
dummy
}

fragment frag1 on Type2 {
dummy
}

mutation m3 {
field
}

fragment frag3 on Type3 {
dummy3
dummy1
dummy2
}

subscription s2 {
dummy
}

# comments for q3
query q3 ($arg2: ID, $arg1: String, $arg3: Float) {
dummy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
schema {
query: Type3
mutation: Type2
subscription: Type1
}

directive @zdir1 on FIELD

directive @zdir2 on INLINE_FRAGMENT

directive @zdir3(arg1: Float, arg2: Int!, arg3: [ID]) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

type Type1 @dir1 @dir2 @dir3 {
f1(arg1: Float, arg2: Int!, arg3: [ID]): String
f2: Float
f3: ID
}

# Type2 comment
"Type2 description"
input Type2 {

"f1 description"
f1: String

"f2 description"
f2: [[Float!]!]!

"f3 description"
f3: ID!
Comment on lines +23 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken indentation.

}

scalar Type3
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# l2 - comments on default query line 1
# l1 - comments on default query line 2
# l3 - comments on default query line 3
{
field1(arg1: [3, 1, 2], arg2: "value1", arg3: {sub1: 2, sub2: 1, sub3: 3})
field2
field3 @dir1(arg1: [3, 1, 2], arg2: "value1", arg3: {sub1: 2, sub2: 1, sub3: 3}) @dir2 @dir3
... {
field4
}
... on Type2 {
field5
}
... on Type3 {
field6
}
...fragment7
...fragment8
...fragment9
}

# comments for q2
query q2 {
dummy
}

# comments for q3
query q3($arg1: String, $arg2: ID, $arg3: Float) {
dummy
}

mutation m1 {
field
}

mutation m2 {
field
}

mutation m3 {
field
}

subscription s1 {
dummy
}

subscription s2 {
dummy
}

subscription s3 @dir1 @dir2 @dir3 {
dummy
}

fragment frag2 on Type1 {
dummy
}

fragment frag1 on Type2 {
dummy
}

fragment frag3 on Type3 {
dummy1
dummy2
dummy3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
query
unnamed(falsey: false, truthy: true)
}

# Copyright (c) 2015, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
query queryName($foo: ComplexType, $site: Site = MOBILE) {
whoever123is: node(id: [123, 456]) {
id
... @skip(unless: $foo) {
id
}
... {
id
}
... on User @defer {
field2 {
alias: field1(after: $foo, first: 10) @include(if: $foo) {
id
...frag
}
id
}
}
}
}

mutation likeStory {
like(story: 123) @defer {
story {
id
}
}
}

mutation updateStory {
like(story: {EndDate: null, id: 123}) {
story {
id
}
}
}

subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) {
storyLikeSubscribe(input: $input) {
story {
likers {
count
}
likeSentence {
text
}
}
}
}

fragment frag on Friend {
foo(bar: $b, obj: {key: "value"}, size: $size)
}

# Copyright (c) 2015, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
schema {
query: QueryType
mutation: MutationType
}

directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

enum AnnotatedEnum @onEnum {
ANNOTATED_VALUE @onEnumValue
OTHER_VALUE
}

input AnnotatedInput @onInputObjectType {
annotatedField: Type @onField
}

interface AnnotatedInterface @onInterface {
annotatedField(arg: Type @onArg): Type @onField
}

type AnnotatedObject @onObject(arg: "value") {
# a comment
annotatedField(arg: Type = "default" @onArg): Type @onField
}

scalar AnnotatedScalar @onScalar

union AnnotatedUnion @onUnion = A | B

interface Bar {
four(argument: String = "string"): String
one: Type
}

scalar CustomScalar

union Feed = Advert | Article | Story

type Foo implements Bar {
five(argument: [String] = ["string", "string"]): String
four(argument: String = "string"): String
# comment 1
one: Type
six(argument: InputType = {key: "value"}): Type
# multiline comments
# with very important description #
# # and symbol # and ##
three(argument: InputType, other: String): Int
# comment 2
two(argument: InputType!): Type
}

input InputType {
answer: Int = 42
key: String!
}

type NoFields

enum Site {
DESKTOP
MOBILE
}

extend type Foo {
seven(argument: [String]): Type
}

extend type Foo @onType
Loading