Class: GraphitiGql::Schema::Fields::Show

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti_gql/schema/fields/show.rb

Instance Method Summary collapse

Constructor Details

#initialize(registered) ⇒ Show

Returns a new instance of Show.



5
6
7
# File 'lib/graphiti_gql/schema/fields/show.rb', line 5

def initialize(registered)
  @registered = registered
end

Instance Method Details

#apply(query) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/graphiti_gql/schema/fields/show.rb', line 9

def apply(query)
  field = query.field name,
    @registered[:type],
    null: true,
    extras: [:lookahead]
  unless @registered[:resource].singular
    field.argument(:id, GraphQL::Types::ID, required: true)
  end
  _registered = @registered
  query.define_method name do |**arguments|
    params = Util.params_from_args(arguments)
    _registered[:resource].find(params).data
  end
end