Class: GraphQL::RakeTask

Inherits:
Object
  • Object
show all
Extended by:
Rake::DSL
Includes:
Rake::DSL
Defined in:
lib/graphql/rake_task.rb,
lib/graphql/rake_task/validate.rb

Overview

A rake task for dumping a schema as IDL or JSON.

By default, schemas are looked up by name as constants using schema_name:. You can provide a load_schema function to return your schema another way.

Use load_context: and visible? to dump schemas under certain visibility constraints.

Examples

Example: Dump a Schema to .graphql + .json files

require "graphql/rake_task"
GraphQL::RakeTask.new(schema_name: "MySchema")

# $ rake graphql:schema:dump
# Schema IDL dumped to ./schema.graphql
# Schema JSON dumped to ./schema.json

Example: Invoking the task from Ruby

require "rake"
Rake::Task["graphql:schema:dump"].invoke

Example: Providing arguments to build the introspection query

require "graphql/rake_task"
GraphQL::RakeTask.new(schema_name: "MySchema", include_is_one_of: true)

Defined Under Namespace

Modules: Validate

Constant Summary collapse

DEFAULT_OPTIONS =
{
  namespace: "graphql",
  dependencies: nil,
  schema_name: nil,
  load_schema: ->(task) { Object.const_get(task.schema_name) },
  load_context: ->(task) { {} },
  directory: ".",
  idl_outfile: "schema.graphql",
  json_outfile: "schema.json",
  include_deprecated_args: true,
  include_schema_description: false,
  include_is_repeatable: false,
  include_specified_by_url: false,
  include_is_one_of: false
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RakeTask

Set the parameters of this task by passing keyword arguments or assigning attributes inside the block



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/graphql/rake_task.rb', line 116

def initialize(options = {})
  all_options = DEFAULT_OPTIONS.merge(options)
  all_options.each do |k, v|
    self.public_send("#{k}=", v)
  end

  if block_given?
    yield(self)
  end

  define_task
end

Instance Attribute Details

#dependencies ⇒ Object

Returns

  • Array<String>


73
74
75
# File 'lib/graphql/rake_task.rb', line 73

def dependencies
  @dependencies
end

#directory ⇒ Object

Returns

  • String — directory for IDL & JSON files


105
106
107
# File 'lib/graphql/rake_task.rb', line 105

def directory
  @directory
end

#idl_outfile ⇒ Object

Returns

  • String — target for IDL task


95
96
97
# File 'lib/graphql/rake_task.rb', line 95

def idl_outfile
  @idl_outfile
end

#include_deprecated_args ⇒ Object

See GraphQL::Schema.as_json.

Returns

  • Boolean — Options for additional fields in the introspection query JSON response


112
113
114
# File 'lib/graphql/rake_task.rb', line 112

def include_deprecated_args
  @include_deprecated_args
end

#include_is_one_of ⇒ Object

See GraphQL::Schema.as_json.

Returns

  • Boolean — Options for additional fields in the introspection query JSON response


112
113
114
# File 'lib/graphql/rake_task.rb', line 112

def include_is_one_of
  @include_is_one_of
end

#include_is_repeatable ⇒ Object

See GraphQL::Schema.as_json.

Returns

  • Boolean — Options for additional fields in the introspection query JSON response


112
113
114
# File 'lib/graphql/rake_task.rb', line 112

def include_is_repeatable
  @include_is_repeatable
end

#include_schema_description ⇒ Object

See GraphQL::Schema.as_json.

Returns

  • Boolean — Options for additional fields in the introspection query JSON response


112
113
114
# File 'lib/graphql/rake_task.rb', line 112

def include_schema_description
  @include_schema_description
end

#include_specified_by_url ⇒ Object

See GraphQL::Schema.as_json.

Returns

  • Boolean — Options for additional fields in the introspection query JSON response


112
113
114
# File 'lib/graphql/rake_task.rb', line 112

def include_specified_by_url
  @include_specified_by_url
end

#json_outfile ⇒ Object

Returns

  • String — target for JSON task


100
101
102
# File 'lib/graphql/rake_task.rb', line 100

def json_outfile
  @json_outfile
end

#load_context ⇒ Object

Returns

  • <#call(task)> — A callable for loading the query context


90
91
92
# File 'lib/graphql/rake_task.rb', line 90

def load_context
  @load_context
end

#load_schema ⇒ Object

Returns

  • <#call(task)> — A proc for loading the target GraphQL schema


85
86
87
# File 'lib/graphql/rake_task.rb', line 85

def load_schema
  @load_schema
end

#namespace=(value) ⇒ Object (writeonly)

Returns

  • String — Namespace for generated tasks


64
65
66
# File 'lib/graphql/rake_task.rb', line 64

def namespace=(value)
  @namespace = value
end

#schema_name ⇒ Object

See load_schema for loading a schema another way

Returns

  • String — By default, used to find the schema as a constant.


80
81
82
# File 'lib/graphql/rake_task.rb', line 80

def schema_name
  @schema_name
end

Instance Method Details

#rake_namespace ⇒ Object



66
67
68
# File 'lib/graphql/rake_task.rb', line 66

def rake_namespace
  @namespace
end