Class: GraphQL::Schema::Field::ConnectionExtension
- Inherits:
-
GraphQL::Schema::FieldExtension
- Object
- GraphQL::Schema::FieldExtension
- GraphQL::Schema::Field::ConnectionExtension
- Defined in:
- lib/graphql/schema/field/connection_extension.rb
Instance Attribute Summary
Attributes inherited from GraphQL::Schema::FieldExtension
#added_default_arguments, #added_extras, #field, #options
Instance Method Summary collapse
-
#after_resolve(value:, object:, arguments:, context:, memo:) ⇒ Object
: (value: untyped, object: untyped, arguments: Hash[Symbol, untyped], context: GraphQL::Query::Context, memo: untyped) -> untyped.
-
#apply ⇒ Object
: -> void.
-
#resolve(arguments:, context:, object: nil, objects: nil) {|object || objects, next_args, original_arguments| ... } ⇒ Object
Remove pagination args before passing it to a user method : (arguments: Hash[Symbol, untyped], context: GraphQL::Query::Context, ?object: untyped, ?objects: untyped) { (untyped, Hash[Symbol, untyped], Hash[Symbol, untyped]) -> untyped } -> untyped.
Methods inherited from GraphQL::Schema::FieldExtension
#after_define, #after_define_apply, default_argument, default_argument_configurations, extras, #initialize
Constructor Details
This class inherits a constructor from GraphQL::Schema::FieldExtension
Instance Method Details
#after_resolve(value:, object:, arguments:, context:, memo:) ⇒ Object
: (value: untyped, object: untyped, arguments: Hash[Symbol, untyped], context: GraphQL::Query::Context, memo: untyped) -> untyped
33 34 35 36 37 38 39 40 41 |
# File 'lib/graphql/schema/field/connection_extension.rb', line 33 def after_resolve(value:, object:, arguments:, context:, memo:) original_arguments = memo lookahead = arguments[:lookahead] context.query.after_lazy(value) do |resolved_value| connection = context.schema.connections.populate_connection(field, object.object, resolved_value, original_arguments, context) connection.lookahead ||= lookahead if connection.is_a?(GraphQL::Pagination::Connection) connection end end |
#apply ⇒ Object
: -> void
12 13 14 15 16 17 |
# File 'lib/graphql/schema/field/connection_extension.rb', line 12 def apply field.argument :after, "String", "Returns the elements in the list that come after the specified cursor.", required: false field.argument :before, "String", "Returns the elements in the list that come before the specified cursor.", required: false field.argument :first, "Int", "Returns the first _n_ elements from the list.", required: false field.argument :last, "Int", "Returns the last _n_ elements from the list.", required: false end |
#resolve(arguments:, context:, object: nil, objects: nil) {|object || objects, next_args, original_arguments| ... } ⇒ Object
Remove pagination args before passing it to a user method : (arguments: Hash[Symbol, untyped], context: GraphQL::Query::Context, ?object: untyped, ?objects: untyped) { (untyped, Hash[Symbol, untyped], Hash[Symbol, untyped]) -> untyped } -> untyped
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/graphql/schema/field/connection_extension.rb', line 21 def resolve(arguments:, context:, object: nil, objects: nil, &block) next_args = arguments.dup next_args.delete(:first) next_args.delete(:last) next_args.delete(:before) next_args.delete(:after) # Keep the extension's extras (`:lookahead`) out of `connection.arguments` original_arguments = added_extras ? arguments.reject { |k, _v| added_extras.include?(k) } : arguments yield(object || objects, next_args, original_arguments) end |