class GraphqlRails::DumpGraphqlSchema

Generates graphql schema dump files

Attributes

name[R]

Public Class Methods

call(*args) click to toggle source
# File lib/graphql_rails/tasks/dump_graphql_schema.rb, line 12
def self.call(*args)
  new(*args).call
end
new(name:) click to toggle source
# File lib/graphql_rails/tasks/dump_graphql_schema.rb, line 16
def initialize(name:)
  @name = name
end

Public Instance Methods

call() click to toggle source
# File lib/graphql_rails/tasks/dump_graphql_schema.rb, line 20
def call
  validate
  File.write(schema_path, schema.to_definition)
end

Private Instance Methods

default_schema_path() click to toggle source
# File lib/graphql_rails/tasks/dump_graphql_schema.rb, line 48
def default_schema_path
  schema_folder_path = Rails.root.join('spec', 'fixtures')

  FileUtils.mkdir_p(schema_folder_path)
  file_name = name.present? ? "graphql_#{name}_schema.graphql" : 'graphql_schema.graphql'

  schema_folder_path.join(file_name)
end
router() click to toggle source
# File lib/graphql_rails/tasks/dump_graphql_schema.rb, line 36
def router
  @router ||= '::GraphqlRouter'.safe_constantize
end
schema() click to toggle source
# File lib/graphql_rails/tasks/dump_graphql_schema.rb, line 40
def schema
  @schema ||= ::GraphqlRouter.graphql_schema(name.presence)
end
schema_path() click to toggle source
# File lib/graphql_rails/tasks/dump_graphql_schema.rb, line 44
def schema_path
  ENV['GRAPHQL_SCHEMA_DUMP_PATH'] || default_schema_path
end
validate() click to toggle source
# File lib/graphql_rails/tasks/dump_graphql_schema.rb, line 27
def validate
  return if router

  error_message = \
    'GraphqlRouter is missing. ' \
    'Run `rails g graphql_rails:install` to build it'
  raise MissingGraphqlRouterError, error_message
end