Class: GraphitiGql::Schema::Fields::Index

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

Instance Method Summary collapse

Constructor Details

#initialize(registered) ⇒ Index

Returns a new instance of Index.



5
6
7
# File 'lib/graphiti_gql/schema/fields/index.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
23
# File 'lib/graphiti_gql/schema/fields/index.rb', line 9

def apply(query)
  resource = @registered[:resource]
  field = query.field resource.graphql_entrypoint,
    @registered[:type].connection_type,
    null: false,
    connection: false,
    extras: [:lookahead]
  field.extension(RelayConnectionExtension, resource: resource)
  ListArguments.new(resource).apply(field)
  query.define_method name do |**arguments|
    params = Util.params_from_args(arguments)
    proxy = resource.all(params)
    ResponseShim.new(proxy.data, proxy)
  end
end