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.

load_context:, only: and except: are supported so that you can keep an eye on how filters affect your schema.

Examples:

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

Invoking the task from Ruby

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

Providing arguments to build the introspection query

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  namespace: "graphql",
  dependencies: nil,
  schema_name: nil,
  load_schema: ->(task) { Object.const_get(task.schema_name) },
  load_context: ->(task) { {} },
  only: nil,
  except: nil,
  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



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/graphql/rake_task.rb', line 92

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

#dependenciesArray<String>

Returns:

  • (Array<String>)


59
60
61
# File 'lib/graphql/rake_task.rb', line 59

def dependencies
  @dependencies
end

#directoryString

Returns directory for IDL & JSON files.

Returns:

  • (String)

    directory for IDL & JSON files



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

def directory
  @directory
end

#except<#call(member, ctx)>?

Returns A filter for this task.

Returns:

  • (<#call(member, ctx)>, nil)

    A filter for this task



75
76
77
# File 'lib/graphql/rake_task.rb', line 75

def except
  @except
end

#idl_outfileString

Returns target for IDL task.

Returns:

  • (String)

    target for IDL task



78
79
80
# File 'lib/graphql/rake_task.rb', line 78

def idl_outfile
  @idl_outfile
end

#include_deprecated_argsBoolean

Returns Options for additional fields in the introspection query JSON response.

Returns:

  • (Boolean)

    Options for additional fields in the introspection query JSON response

See Also:



88
89
90
# File 'lib/graphql/rake_task.rb', line 88

def include_deprecated_args
  @include_deprecated_args
end

#include_is_one_ofBoolean

Returns Options for additional fields in the introspection query JSON response.

Returns:

  • (Boolean)

    Options for additional fields in the introspection query JSON response

See Also:



88
89
90
# File 'lib/graphql/rake_task.rb', line 88

def include_is_one_of
  @include_is_one_of
end

#include_is_repeatableBoolean

Returns Options for additional fields in the introspection query JSON response.

Returns:

  • (Boolean)

    Options for additional fields in the introspection query JSON response

See Also:



88
89
90
# File 'lib/graphql/rake_task.rb', line 88

def include_is_repeatable
  @include_is_repeatable
end

#include_schema_descriptionBoolean

Returns Options for additional fields in the introspection query JSON response.

Returns:

  • (Boolean)

    Options for additional fields in the introspection query JSON response

See Also:



88
89
90
# File 'lib/graphql/rake_task.rb', line 88

def include_schema_description
  @include_schema_description
end

#include_specified_by_urlBoolean

Returns Options for additional fields in the introspection query JSON response.

Returns:

  • (Boolean)

    Options for additional fields in the introspection query JSON response

See Also:



88
89
90
# File 'lib/graphql/rake_task.rb', line 88

def include_specified_by_url
  @include_specified_by_url
end

#json_outfileString

Returns target for JSON task.

Returns:

  • (String)

    target for JSON task



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

def json_outfile
  @json_outfile
end

#load_context<#call(task)>

Returns A callable for loading the query context.

Returns:

  • (<#call(task)>)

    A callable for loading the query context



69
70
71
# File 'lib/graphql/rake_task.rb', line 69

def load_context
  @load_context
end

#load_schema<#call(task)>

Returns A proc for loading the target GraphQL schema.

Returns:

  • (<#call(task)>)

    A proc for loading the target GraphQL schema



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

def load_schema
  @load_schema
end

#namespace=(value) ⇒ String (writeonly)

Returns Namespace for generated tasks.

Returns:

  • (String)

    Namespace for generated tasks



52
53
54
# File 'lib/graphql/rake_task.rb', line 52

def namespace=(value)
  @namespace = value
end

#only<#call(member, ctx)>?

Returns A filter for this task.

Returns:

  • (<#call(member, ctx)>, nil)

    A filter for this task



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

def only
  @only
end

#schema_nameString

Returns By default, used to find the schema as a constant.

Returns:

  • (String)

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

See Also:

  • for loading a schema another way


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

def schema_name
  @schema_name
end

Instance Method Details

#rake_namespaceObject



54
55
56
# File 'lib/graphql/rake_task.rb', line 54

def rake_namespace
  @namespace
end