Class: GraphQL::RemoteLoader::Loader

Inherits:
Batch::Loader
  • Object
show all
Defined in:
lib/graphql/remote_loader/loader.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load(query) ⇒ Object

Delegates to GraphQL::Batch::Loader#load We include a unique prime as part of the batch key to use as part of the alias on all fields. This is used to a) Avoid name collisions in the generated query b) Determine which fields in the result JSON should be

handed fulfilled to each promise


14
15
16
17
18
19
20
21
# File 'lib/graphql/remote_loader/loader.rb', line 14

def self.load(query)
  @index ||= 1
  @index += 1

  prime = Prime.take(@index - 1).last

  self.for.load([query, prime])
end

.reset_indexObject



23
24
25
# File 'lib/graphql/remote_loader/loader.rb', line 23

def self.reset_index
  @index = nil
end

Instance Method Details

#query(query_string) ⇒ Object

Given a query string, return a response JSON

Raises:

  • (NotImplementedError)


28
29
30
31
# File 'lib/graphql/remote_loader/loader.rb', line 28

def query(query_string)
  raise NotImplementedError,
    "RemoteLoader::Loader should be subclassed and #query must be defined"
end