Class: GraphQL::Upgrader::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/upgrader/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Schema

Returns a new instance of Schema.


6
7
8
# File 'lib/graphql/upgrader/schema.rb', line 6

def initialize(schema)
  @schema = schema
end

Instance Method Details

#upgradeObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graphql/upgrader/schema.rb', line 10

def upgrade
  transformable = schema.dup

  transformable.sub!(
    /([a-zA-Z_0-9]*) = GraphQL::Schema\.define do/, 'class \1 < GraphQL::Schema'
  )

  transformable.sub!(
    /object_from_id ->\s?\((.*)\) do/, 'def self.object_from_id(\1)'
  )

  transformable.sub!(
    /resolve_type ->\s?\((.*)\) do/, 'def self.resolve_type(\1)'
  )

  transformable.sub!(
    /id_from_object ->\s?\((.*)\) do/, 'def self.id_from_object(\1)'
  )

  transformable
end