Class: GraphQL::Relay::ConnectionField
- Inherits:
-
Object
- Object
- GraphQL::Relay::ConnectionField
- Defined in:
- lib/graphql/relay/connection_field.rb
Overview
Provided a GraphQL field which returns a collection of items, ‘ConnectionField.create` modifies that field to expose those items as a collection.
The original resolve proc is used to fetch items, then a connection implementation is fetched with BaseConnection.connection_for_items.
Constant Summary collapse
- ARGUMENT_DEFINITIONS =
[ [:first, GraphQL::INT_TYPE], [:after, GraphQL::STRING_TYPE], [:last, GraphQL::INT_TYPE], [:before, GraphQL::STRING_TYPE], ]
- DEFAULT_ARGUMENTS =
ARGUMENT_DEFINITIONS.reduce({}) do |memo, arg_defn| argument = GraphQL::Argument.new argument.name = arg_defn[0] argument.type = arg_defn[1] memo[argument.name.to_s] = argument memo end
Class Method Summary collapse
-
.create(underlying_field, max_page_size: nil) ⇒ GraphQL::Field
Turn A GraphQL::Field into a connection by: - Merging in the default arguments - Transforming its resolve function to return a connection object.
Class Method Details
.create(underlying_field, max_page_size: nil) ⇒ GraphQL::Field
Turn A GraphQL::Field into a connection by:
-
Merging in the default arguments
-
Transforming its resolve function to return a connection object
31 32 33 34 35 36 |
# File 'lib/graphql/relay/connection_field.rb', line 31 def self.create(, max_page_size: nil) .arguments = DEFAULT_ARGUMENTS.merge(.arguments) original_resolve = .resolve_proc .resolve = get_connection_resolve(.name, original_resolve, max_page_size: max_page_size) end |