Skip to content
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

fix: sort inline fragments by their type name #16

Merged
merged 1 commit into from
Feb 14, 2023
Merged

fix: sort inline fragments by their type name #16

merged 1 commit into from
Feb 14, 2023

Conversation

rperryng
Copy link
Owner

@rperryng rperryng commented Feb 9, 2023

inline fragment nodes do not have a name method, causing the GraphQL::Hive::Printer to raise an error when trying to sort a list of selection nodes that contain an inline fragment.

NoMethodError:
  undefined method `name' for #<GraphQL::Language::Nodes::InlineFragment:0x00000001048e5530 @line=5, @col=11, @filename=nil, @type=#<GraphQL::Language::Nodes::TypeName:0x00000001048e5bc0 @filename=nil, @name="HasAuthor">, @selections=[#<GraphQL::Language::Nodes::Field:0x00000001048e5698 @line=6, @col=13, @filename=nil, @name="author", @arguments=[], @directives=[], @selections=[#<GraphQL::Language::Nodes::Field:0x00000001048e5878 @line=7, @col=15, @filename=nil, @name="name", @arguments=[], @directives=[], @selections=[], @alias=nil>], @alias=nil>], @directives=[]>

          super(selections.sort_by(&:name), indent: indent)
                          ^^^^^^^^
# ./lib/graphql-hive/printer.rb:36:in `each'
# ./lib/graphql-hive/printer.rb:36:in `sort_by'
# ./lib/graphql-hive/printer.rb:36:in `print_selections'
# ./lib/graphql-hive/printer.rb:26:in `print_field'
<GraphQL::Language::Nodes::InlineFragment:0x0000000106e0b828
 @col=11,
 @directives=[],
 @filename=nil,
 @line=10,
 @selections=
  [#<GraphQL::Language::Nodes::Field:0x0000000106e0b968
    @alias=nil,
    @arguments=[],
    @col=13,
    @directives=[],
    @filename=nil,
    @line=11,
    @name="publisher",
    @selections=[#<GraphQL::Language::Nodes::Field:0x0000000106e0baa8 @alias=nil, @arguments=[], @col=15, @directives=[], @filename=nil, @line=12, @name="name", @selections=[]>]>],
 @type=#<GraphQL::Language::Nodes::TypeName:0x0000000106e0bc60 @filename=nil, @name="HasPublisher">>

@rperryng rperryng merged commit 56aa558 into rperryng:master Feb 14, 2023
@rperryng rperryng mentioned this pull request Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant