Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module SchemaDefinition
)
end

it "produces the same GraphQL output, regardless of the order the types are defined in" do
it "produces byte-identical GraphQL output, regardless of the order the types are defined in" do
object_type_definitions = {
"Component" => lambda do |t|
t.field "id", "ID!"
Expand Down Expand Up @@ -129,18 +129,24 @@ module SchemaDefinition
%w[WidgetVersion Component Widget]
]

uniq_results_for_each_ordering = all_definition_orderings.map do |type_names_in_order|
define_schema do |schema|
results_by_definition_order = all_definition_orderings.to_h do |type_names_in_order|
result = define_schema do |schema|
type_names_in_order.each do |type_name|
schema.object_type(type_name, &object_type_definitions.fetch(type_name))
end
end
end.uniq

expect(uniq_results_for_each_ordering.size).to eq 1
[type_names_in_order, result]
end

reference_order, reference_result = results_by_definition_order.first

# Also compare the first and last, so that if there are multiple we get a diff showing how they differ.
expect(uniq_results_for_each_ordering.first).to eq uniq_results_for_each_ordering.last
# Compare the raw generated SDL rather than normalizing it through graphql-ruby. Schema definition
# order must not affect field order or any other part of the generated schema artifact.
results_by_definition_order.drop(1).each do |definition_order, result|
Comment on lines +142 to +146

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
reference_order, reference_result = results_by_definition_order.first
# Also compare the first and last, so that if there are multiple we get a diff showing how they differ.
expect(uniq_results_for_each_ordering.first).to eq uniq_results_for_each_ordering.last
# Compare the raw generated SDL rather than normalizing it through graphql-ruby. Schema definition
# order must not affect field order or any other part of the generated schema artifact.
results_by_definition_order.drop(1).each do |definition_order, result|
(reference_order, reference_result), *remaining_results = results_by_definition_order
# Compare the raw generated SDL rather than normalizing it through graphql-ruby. Schema definition
# order must not affect field order or any other part of the generated schema artifact.
remaining_results.each do |definition_order, result|

I was initially confused by the drop(1). Note: I haven't tried this, so it may not quite work as I've written it. Pattern matching syntax might be needed to make it work.

expect(result).to eq(reference_result),
"Expected definition order #{definition_order.inspect} to match #{reference_order.inspect}"
end
end

it "returns reasonably-sized strings from `#inspect` and `#to_s` for all objects exposed to users so that the exception output if the user misspells a method name is readable" do
Expand Down