Skip to content

Commit

Permalink
Sort types in generated schema
Browse files Browse the repository at this point in the history
Otherwise, added types order may depend on file load order which is not
always deterministic if the files don't depend on each other.
  • Loading branch information
PChambino committed Mar 14, 2022
1 parent 7cac442 commit 3ba4c66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/graphiti/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def generate

def generate_types
{}.tap do |types|
Graphiti::Types.map.each_pair do |name, config|
Graphiti::Types.map.sort.each_entry do |name, config|
types[name] = config.slice(:kind, :description)
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ def self.name
expect(schema[:types]).to eq(expected[:types])
end

it "has sorted types" do
expect(schema[:types].to_a).to eq(expected[:types].sort)
end

# Dynamically-created resources, e.g. remote resources
context "when resource has missing name" do
let(:no_name) do
Expand Down

0 comments on commit 3ba4c66

Please sign in to comment.