Class: GraphQL::Schema::Field::ConnectionExtension

Inherits:
GraphQL::Schema::FieldExtension show all
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

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



24
25
26
27
28
29
# File 'lib/graphql/schema/field/connection_extension.rb', line 24

def after_resolve(value:, object:, arguments:, context:, memo:)
  original_arguments = memo
  context.query.after_lazy(value) do |resolved_value|
    context.schema.connections.populate_connection(field, object.object, resolved_value, original_arguments, context)
  end
end

#applyObject



7
8
9
10
11
12
# File 'lib/graphql/schema/field/connection_extension.rb', line 7

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(object: nil, objects: nil, arguments:, context:) {|object || objects, next_args, arguments| ... } ⇒ Object

Remove pagination args before passing it to a user method

Yields:



15
16
17
18
19
20
21
22
# File 'lib/graphql/schema/field/connection_extension.rb', line 15

def resolve(object: nil, objects: nil, arguments:, context:)
  next_args = arguments.dup
  next_args.delete(:first)
  next_args.delete(:last)
  next_args.delete(:before)
  next_args.delete(:after)
  yield(object || objects, next_args, arguments)
end