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

Accept additional options in global_id_field macro #3196

Merged
merged 1 commit into from
Oct 21, 2020
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
4 changes: 2 additions & 2 deletions lib/graphql/define/assign_global_id_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
module GraphQL
module Define
module AssignGlobalIdField
def self.call(type_defn, field_name)
def self.call(type_defn, field_name, **field_kwargs)
resolve = GraphQL::Relay::GlobalIdResolve.new(type: type_defn)
GraphQL::Define::AssignObjectField.call(type_defn, field_name, type: GraphQL::ID_TYPE.to_non_null_type, resolve: resolve)
GraphQL::Define::AssignObjectField.call(type_defn, field_name, **field_kwargs, type: GraphQL::ID_TYPE.to_non_null_type, resolve: resolve)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/graphql/schema/member/has_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def field_class(new_field_class = nil)
end
end

def global_id_field(field_name)
def global_id_field(field_name, **kwargs)
id_resolver = GraphQL::Relay::GlobalIdResolve.new(type: self)
field field_name, "ID", null: false
field field_name, "ID", **kwargs, null: false
define_method(field_name) do
id_resolver.call(object, {}, context)
end
Expand Down
3 changes: 2 additions & 1 deletion spec/graphql/schema/interface_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,14 @@ def resolve_type(_object, _context)
object = Module.new do
include GraphQL::Schema::Interface
graphql_name 'GlobalIdFieldTest'
global_id_field :uuid
global_id_field :uuid, description: 'The UUID field'
end.to_graphql

uuid_field = object.fields["uuid"]

assert_equal GraphQL::NonNullType, uuid_field.type.class
assert_equal GraphQL::ScalarType, uuid_field.type.unwrap.class
assert_equal 'The UUID field', uuid_field.description
assert_equal(
GraphQL::Schema::Member::GraphQLTypeNames::ID,
uuid_field.type.unwrap.name
Expand Down