Skip to content

Commit

Permalink
Merge pull request #3196 from barthez/add-options-to-global-id-field
Browse files Browse the repository at this point in the history
Accept additional options in global_id_field macro
  • Loading branch information
Robert Mosolgo authored Oct 21, 2020
2 parents dbb9f38 + f28222b commit 97a0a06
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
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

0 comments on commit 97a0a06

Please sign in to comment.