3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/graphql_pagination/collection_type.rb', line 3
def collection_type(
collection_base: GraphQL::Schema::Object,
metadata_type: GraphqlPagination::CollectionMetadataType
)
fail CollectionBaseError unless collection_base <= GraphQL::Schema::Object
@collection_types ||= {}
@collection_types[collection_base] ||= {}
@collection_types[collection_base][metadata_type] ||= begin
type_name = "#{graphql_name}Collection"
source_type = self
Class.new(collection_base) do
graphql_name type_name
description "#{graphql_name} type"
field :collection, [source_type], null: false, description: "A collection of paginated #{graphql_name}"
field :metadata, metadata_type, null: false, description: "Pagination Metadata for navigating the Pagination"
def collection
object
end
def metadata
object
end
end
end
end
|