Module: GraphQL::BackwardsCompatibility Private

Defined in:
lib/graphql/backwards_compatibility.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helpers for migrating in a backwards-compatibile way

Defined Under Namespace

Classes: ArityWrapper

Class Method Summary collapse

Class Method Details

.get_arity(callable) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
29
30
31
32
33
# File 'lib/graphql/backwards_compatibility.rb', line 26

def get_arity(callable)
  case callable
  when Method, Proc
    callable.arity
  else
    callable.method(:call).arity
  end
end

.wrap_arity(callable, from:, to:, name:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Given a callable whose API used to take from arguments, check its arity, and if needed, apply a wrapper so that it can be called with to arguments. If a wrapper is applied, warn the application with name.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/graphql/backwards_compatibility.rb', line 11

def wrap_arity(callable, from:, to:, name:)
  arity = get_arity(callable)
  case arity
  when to
    # It already matches, return it as is
    callable
  when from
    # It has the old arity, so wrap it with an arity converter
    warn("#{name} with #{from} arguments is deprecated, it now accepts #{to} arguments")
    ArityWrapper.new(callable, from)
  else
    raise "Can't wrap #{callable} (arity: #{arity}) to have arity #{to}"
  end
end