Skip to content

Consider id field addition dangerous #42

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion lib/graphql/schema_comparator/changes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,11 @@ class FieldAdded < AbstractChange
attr_reader :object_type, :field, :criticality

def initialize(object_type, field)
@criticality = Changes::Criticality.non_breaking
@criticality = if field.graphql_name == 'id'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps it should be possible to customize this?

For instance,

  • Apollo's InMemoryCache looks for id or _id by default
  • ESLint-Plugin-GraphQL's required-fields rule is customizable and uses uuid in its example

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 I think customizing this might go into "linter" territory? Especially beyond the initial id only proposal.

Anyone consuming this library is free to do whatever they want with the output of course.

Changes::Criticality.dangerous('this can blow up linters and change caching behaviour')
else
Changes::Criticality.non_breaking
end
@object_type = object_type
@field = field
end
Expand Down
22 changes: 22 additions & 0 deletions test/lib/graphql/schema_comparator/changes/field_added_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "test_helper"

class GraphQL::SchemaComparator::Changes::FieldAddedTest < Minitest::Test
def test_criticality_is_non_breaking_by_default
change = GraphQL::SchemaComparator::Changes::FieldAdded.new(
GraphQL::ObjectType.define { name "Type" },
GraphQL::Field.define { name "field" },
)

assert change.non_breaking?
end

def test_criticality_is_dangerous_for_id_field_addition
change = GraphQL::SchemaComparator::Changes::FieldAdded.new(
GraphQL::ObjectType.define { name "Type" },
GraphQL::Field.define { name "id" },
)

assert change.dangerous?
assert_equal 'this can blow up linters and change caching behaviour', change.message
end
end