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, "Returns the first _n_ elements from the list."], ["after", GraphQL::STRING_TYPE, "Returns the elements in the list that come after the specified global ID."], ["last", GraphQL::INT_TYPE, "Returns the last _n_ elements from the list."], ["before", GraphQL::STRING_TYPE, "Returns the elements in the list that come before the specified global ID."], ]
- DEFAULT_ARGUMENTS =
ARGUMENT_DEFINITIONS.reduce({}) do |memo, arg_defn| argument = GraphQL::Argument.new name, type, description = arg_defn argument.name = name argument.type = type argument.description = description 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
33 34 35 36 37 38 |
# File 'lib/graphql/relay/connection_field.rb', line 33 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 |