graphql-schema_directives 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +57 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/LICENSE +21 -0
- data/README.md +229 -0
- data/Rakefile +12 -0
- data/graphql-schema_directives.gemspec +33 -0
- data/lib/graphql-schema_directives.rb +4 -0
- data/lib/graphql/schema_directives.rb +12 -0
- data/lib/graphql/schema_directives/has_directives.rb +23 -0
- data/lib/graphql/schema_directives/initialize_with_directives.rb +17 -0
- data/lib/graphql/schema_directives/schema_directives_document_from_schema_definition.rb +72 -0
- data/lib/graphql/schema_directives/types.rb +71 -0
- data/lib/graphql/schema_directives/version.rb +7 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 706240fbd69fe3d0ea90204ba750384c0d7c0ed3a3527fc6a73d082aa39f7f2e
|
4
|
+
data.tar.gz: c8e509e2f8ec18da0a796c39fd70e16b17e21ba9732a8fc563076d450ec73a70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a4b743c704ecd03f81d88e3d97ebce34a5f86b2c20f1cae78ac4b1462f61f586ff51a9a6685add1440023e1dce34099b8395a990c1f096cc9f509f1f4441f1e
|
7
|
+
data.tar.gz: 38edcc3f38b0bce7df416dd960db3d1e85add720bbf1a2b3aa185149738b089e5b01916fa6ef35da4eedb959cb448c4b07539023df438c4452d4cf24e128f4fd
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
.DS_Store
|
55
|
+
|
56
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
57
|
+
# .rubocop-https?--*
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
graphql-schema_directives (0.0.1)
|
5
|
+
graphql (~> 1.9)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
graphql (1.11.6)
|
11
|
+
minitest (5.14.2)
|
12
|
+
rake (12.3.3)
|
13
|
+
warning (1.1.0)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 2.0)
|
20
|
+
graphql-schema_directives!
|
21
|
+
minitest (~> 5.12)
|
22
|
+
rake (~> 12.0)
|
23
|
+
warning (~> 1.1)
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
2.1.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Greg MacWilliam
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,229 @@
|
|
1
|
+
# Ruby GraphQL Schema Directives
|
2
|
+
|
3
|
+
This gem extends [GraphQL Ruby](http://graphql-ruby.org/) to add support for custom schema directives that annotate an SDL. These annotations are useful for [Schema Stitching](https://www.graphql-tools.com/docs/stitch-directives-sdl), [Apollo Federation](https://www.apollographql.com/docs/federation/), and other proprietary uses.
|
4
|
+
|
5
|
+
This gem is intentionally generic, versus the [apollo-federation](https://github.com/Gusto/apollo-federation-ruby) gem upon which it is based. The goals of this gem are much simpler:
|
6
|
+
|
7
|
+
1. allow schema directives to be applied to any GraphQL element, and then printed into an annotated SDL.
|
8
|
+
2. allow class-based schemas and parsed `GraphQL::Schema.from_definition` schemas to be combined and printed together.
|
9
|
+
|
10
|
+
## Table of Contents
|
11
|
+
|
12
|
+
- [Installation](#installation)
|
13
|
+
- [Class-based schemas](#class-based-schemas)
|
14
|
+
- [Schemas from definition](#schemas-from-definition)
|
15
|
+
- [Schema Stitching SDL](#schema-stitching-sdl)
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add to Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'graphql-schema_directives'
|
23
|
+
```
|
24
|
+
|
25
|
+
Then install:
|
26
|
+
|
27
|
+
```shell
|
28
|
+
bundle install
|
29
|
+
```
|
30
|
+
|
31
|
+
## Class-based schemas
|
32
|
+
|
33
|
+
There's a typed mixin available for extending all GraphQL schema members.
|
34
|
+
|
35
|
+
### Schema classes
|
36
|
+
|
37
|
+
Include the schema mixin:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class MySchema < GraphQL::Schema
|
41
|
+
include GraphQL::SchemaDirectives::Schema
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
This adds a `print_schema_with_directives` method to print an SDL that includes custom schema directives:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
MySchema.print_schema_with_directives
|
49
|
+
```
|
50
|
+
|
51
|
+
### Field, Object & Interface classes
|
52
|
+
|
53
|
+
Setup base abstracts:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class BaseField < GraphQL::Schema::Field
|
57
|
+
include GraphQL::SchemaDirectives::Field
|
58
|
+
end
|
59
|
+
|
60
|
+
class BaseObject < GraphQL::Schema::Object
|
61
|
+
include GraphQL::SchemaDirectives::Object
|
62
|
+
field_class BaseField
|
63
|
+
end
|
64
|
+
|
65
|
+
module BaseInterface
|
66
|
+
include GraphQL::Schema::Interface
|
67
|
+
include GraphQL::SchemaDirectives::Interface
|
68
|
+
field_class BaseField
|
69
|
+
end
|
70
|
+
```
|
71
|
+
|
72
|
+
Then extend into concrete implementations:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
module Spaceship
|
76
|
+
include BaseInterface
|
77
|
+
add_directive :attribute, { speed: 'average' }
|
78
|
+
|
79
|
+
field :name, String, null: false, directives: {
|
80
|
+
cost: { value: 'FIELD' },
|
81
|
+
public: nil
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
class XWing < BaseObject
|
86
|
+
implements Spaceship
|
87
|
+
add_directive :attribute, { speed: 'fast' }
|
88
|
+
add_directive :rebel
|
89
|
+
|
90
|
+
field :name, String, null: false, directives: {
|
91
|
+
cost: { value: 'FIELD' },
|
92
|
+
public: nil
|
93
|
+
}
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
Prints from `schema.print_schema_with_directives` as:
|
98
|
+
|
99
|
+
```graphql
|
100
|
+
interface Spaceship @attribute(speed: "average") {
|
101
|
+
name: String! @cost(value: "FIELD") @public
|
102
|
+
}
|
103
|
+
|
104
|
+
type XWing @attribute(speed: "fast") @rebel {
|
105
|
+
name: String! @cost(value: "FIELD") @public
|
106
|
+
}
|
107
|
+
```
|
108
|
+
|
109
|
+
### Argument & InputObject classes
|
110
|
+
|
111
|
+
Base abstracts:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
class BaseArgument < GraphQL::Schema::Argument
|
115
|
+
include GraphQL::SchemaDirectives::Argument
|
116
|
+
end
|
117
|
+
|
118
|
+
class BaseInputObject < GraphQL::Schema::InputObject
|
119
|
+
include GraphQL::SchemaDirectives::InputObject
|
120
|
+
argument_class BaseArgument
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
Concrete implementation:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
class FormInput < BaseInputObject
|
128
|
+
add_directive :oneField
|
129
|
+
argument :choice, String, required: true, directives: {
|
130
|
+
cost: { value: 'INPUT' },
|
131
|
+
public: nil
|
132
|
+
}
|
133
|
+
end
|
134
|
+
```
|
135
|
+
|
136
|
+
Prints as:
|
137
|
+
|
138
|
+
```graphql
|
139
|
+
input FormInput @oneField {
|
140
|
+
choice: String! @cost(value: "INPUT") @public
|
141
|
+
}
|
142
|
+
```
|
143
|
+
|
144
|
+
### EnumValue & Enum classes
|
145
|
+
|
146
|
+
Base abstracts:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
class BaseEnumValue < GraphQL::Schema::EnumValue
|
150
|
+
include GraphQL::SchemaDirectives::EnumValue
|
151
|
+
end
|
152
|
+
|
153
|
+
class BaseEnum < GraphQL::Schema::Enum
|
154
|
+
include GraphQL::SchemaDirectives::Enum
|
155
|
+
enum_value_class BaseEnumValue
|
156
|
+
end
|
157
|
+
```
|
158
|
+
|
159
|
+
Concrete implementation:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
class FormOption < BaseEnum
|
163
|
+
add_directive :dunno
|
164
|
+
value 'GET', directives: { cost: { value: 'READ' }, public: nil }
|
165
|
+
value 'SET', directives: { cost: { value: 'WRITE' }, public: nil }
|
166
|
+
end
|
167
|
+
```
|
168
|
+
|
169
|
+
Prints as:
|
170
|
+
|
171
|
+
```graphql
|
172
|
+
enum FormOption @dunno {
|
173
|
+
GET @cost(value: "READ") @public
|
174
|
+
SET @cost(value: "WRITE") @public
|
175
|
+
}
|
176
|
+
```
|
177
|
+
|
178
|
+
### Other classes
|
179
|
+
|
180
|
+
Base abstracts:
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
class BaseUnion < GraphQL::Schema::Union
|
184
|
+
include GraphQL::SchemaDirectives::Union
|
185
|
+
end
|
186
|
+
|
187
|
+
class BaseScalar < GraphQL::Schema::Scalar
|
188
|
+
include GraphQL::SchemaDirectives::Scalar
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
## Schemas from definition
|
193
|
+
|
194
|
+
You may also [parse and print SDLs](https://graphql-ruby.org/schema/sdl.html) using the gem's `from_definition` method:
|
195
|
+
|
196
|
+
```rb
|
197
|
+
schema = GraphQL::SchemaDirectives.from_definition(type_defs)
|
198
|
+
puts schema.print_schema_with_directives
|
199
|
+
```
|
200
|
+
|
201
|
+
The local `from_definition` method accepts all the same options as [the underlying method](https://graphql-ruby.org/api-doc/1.11.6/GraphQL/Schema#from_definition-class_method). Calling `print_schema_with_directives` works exactly like the [default printer](https://graphql-ruby.org/api-doc/1.11.6/GraphQL/Language/Printer.html#print-instance_method) when operating on an unmodified document parse (elements with an original AST will print their schema directives natively).
|
202
|
+
|
203
|
+
This feature becomes useful when you start modifying a parsed document with class-based additions:
|
204
|
+
|
205
|
+
```rb
|
206
|
+
module Spaceship
|
207
|
+
include GraphQL::Schema::Interface
|
208
|
+
include GraphQL::SchemaDirectives::Interface
|
209
|
+
field :name, String, null: false, directives: { public: nil }
|
210
|
+
end
|
211
|
+
|
212
|
+
type_defs = %(
|
213
|
+
type XWing {
|
214
|
+
name: String! @public
|
215
|
+
}
|
216
|
+
type Query {
|
217
|
+
ship: XWing
|
218
|
+
}
|
219
|
+
schema {
|
220
|
+
query: Query
|
221
|
+
}
|
222
|
+
)
|
223
|
+
|
224
|
+
schema = GraphQL::SchemaDirectives.from_definition(type_defs)
|
225
|
+
schema.types['XWing'].implements(Spaceship)
|
226
|
+
puts schema.print_schema_with_directives
|
227
|
+
```
|
228
|
+
|
229
|
+
Using `print_schema_with_directives` will include directives from the original AST as well as directives applied to added classes.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'graphql/schema_directives/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'graphql-schema_directives'
|
8
|
+
spec.version = GraphQL::SchemaDirectives::VERSION
|
9
|
+
spec.authors = ['Greg MacWilliam']
|
10
|
+
spec.summary = 'Schema directives for graphql-ruby'
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = 'https://github.com/gmac/graphql-schema-directives-ruby'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = '>= 2.2.0'
|
15
|
+
|
16
|
+
spec.metadata = {
|
17
|
+
'homepage_uri' => 'https://github.com/gmac/graphql-schema-directives-ruby',
|
18
|
+
'changelog_uri' => 'https://github.com/gmac/graphql-schema-directives-ruby/releases',
|
19
|
+
'source_code_uri' => 'https://github.com/gmac/graphql-schema-directives-ruby',
|
20
|
+
'bug_tracker_uri' => 'https://github.com/gmac/graphql-schema-directives-ruby/issues',
|
21
|
+
}
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
f.match(%r{^test/})
|
25
|
+
end
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency 'graphql', '~> 1.9'
|
29
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
30
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
31
|
+
spec.add_development_dependency 'minitest', '~> 5.12'
|
32
|
+
spec.add_development_dependency 'warning', '~> 1.1'
|
33
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql/schema_directives/version'
|
4
|
+
require 'graphql/schema_directives/types'
|
5
|
+
|
6
|
+
module GraphQL::SchemaDirectives
|
7
|
+
def self.from_definition(*args, **kwargs, &block)
|
8
|
+
schema = GraphQL::Schema.from_definition(*args, **kwargs, &block)
|
9
|
+
schema.include(GraphQL::SchemaDirectives::Schema)
|
10
|
+
schema
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GraphQL::SchemaDirectives
|
4
|
+
module HasDirectives
|
5
|
+
attr_reader :schema_directives
|
6
|
+
|
7
|
+
def add_directive(name, arguments=nil)
|
8
|
+
raise ArgumentError, 'directive name must be a string or symbol' unless name.is_a?(String) || name.is_a?(Symbol)
|
9
|
+
raise ArgumentError, 'directive arguments must be a Hash or nil' unless arguments.is_a?(Hash) || arguments.nil?
|
10
|
+
@schema_directives ||= []
|
11
|
+
@schema_directives << {
|
12
|
+
name: name,
|
13
|
+
arguments: arguments
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_graphql
|
18
|
+
type = super
|
19
|
+
type.metadata[:schema_directives] = @schema_directives
|
20
|
+
type
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './has_directives'
|
4
|
+
|
5
|
+
module GraphQL::SchemaDirectives
|
6
|
+
module InitializeWithDirectives
|
7
|
+
include HasDirectives
|
8
|
+
|
9
|
+
def initialize(*args, directives: nil, **kwargs, &block)
|
10
|
+
if directives
|
11
|
+
raise ArgumentError, 'schema directives must be a hash' unless directives.is_a?(Hash)
|
12
|
+
directives.each_pair { |name, arguments| add_directive(name, arguments) }
|
13
|
+
end
|
14
|
+
super(*args, **kwargs, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql'
|
4
|
+
|
5
|
+
module GraphQL::SchemaDirectives
|
6
|
+
class SchemaDirectivesDocumentFromSchemaDefinition < GraphQL::Language::DocumentFromSchemaDefinition
|
7
|
+
|
8
|
+
def build_object_type_node(object_type)
|
9
|
+
node = super
|
10
|
+
merge_directives(node, object_type)
|
11
|
+
end
|
12
|
+
|
13
|
+
def build_interface_type_node(interface_type)
|
14
|
+
node = super
|
15
|
+
merge_directives(node, interface_type)
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_field_node(field_type)
|
19
|
+
node = super
|
20
|
+
merge_directives(node, field_type)
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_input_object_node(input_object)
|
24
|
+
node = super
|
25
|
+
merge_directives(node, input_object)
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_argument_node(argument)
|
29
|
+
node = super
|
30
|
+
merge_directives(node, argument)
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_union_type_node(union_type)
|
34
|
+
node = super
|
35
|
+
merge_directives(node, union_type)
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_enum_type_node(enum_type)
|
39
|
+
node = super
|
40
|
+
merge_directives(node, enum_type)
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_enum_value_node(enum_value)
|
44
|
+
node = super
|
45
|
+
merge_directives(node, enum_value)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def merge_directives(node, member)
|
51
|
+
directives = if member.respond_to?(:metadata)
|
52
|
+
member.metadata[:schema_directives]
|
53
|
+
elsif member.respond_to?(:schema_directives)
|
54
|
+
member.schema_directives
|
55
|
+
end
|
56
|
+
|
57
|
+
(directives || []).each do |directive|
|
58
|
+
node = node.merge_directive(
|
59
|
+
name: directive[:name],
|
60
|
+
arguments: build_arguments_node(directive[:arguments]),
|
61
|
+
)
|
62
|
+
end
|
63
|
+
node
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_arguments_node(arguments)
|
67
|
+
(arguments || {}).map do |name, values|
|
68
|
+
GraphQL::Language::Nodes::Argument.new(name: name, value: values)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql'
|
4
|
+
require_relative './has_directives'
|
5
|
+
require_relative './initialize_with_directives'
|
6
|
+
require_relative './schema_directives_document_from_schema_definition'
|
7
|
+
|
8
|
+
module GraphQL::SchemaDirectives
|
9
|
+
module Argument
|
10
|
+
include InitializeWithDirectives
|
11
|
+
end
|
12
|
+
|
13
|
+
module Enum
|
14
|
+
def self.included(klass)
|
15
|
+
klass.extend(HasDirectives)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module EnumValue
|
20
|
+
include InitializeWithDirectives
|
21
|
+
end
|
22
|
+
|
23
|
+
module Field
|
24
|
+
include InitializeWithDirectives
|
25
|
+
end
|
26
|
+
|
27
|
+
module InputObject
|
28
|
+
def self.included(klass)
|
29
|
+
klass.extend(HasDirectives)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Interface
|
34
|
+
def self.included(klass)
|
35
|
+
klass.definition_methods do
|
36
|
+
include HasDirectives
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Object
|
42
|
+
def self.included(klass)
|
43
|
+
klass.extend(HasDirectives)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Scalar
|
48
|
+
def self.included(klass)
|
49
|
+
klass.extend(HasDirectives)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module Schema
|
54
|
+
def self.included(klass)
|
55
|
+
klass.extend(ClassMethods)
|
56
|
+
end
|
57
|
+
|
58
|
+
module ClassMethods
|
59
|
+
def print_schema_with_directives(context: nil)
|
60
|
+
document_from_schema = SchemaDirectivesDocumentFromSchemaDefinition.new(self, context: context)
|
61
|
+
GraphQL::Language::Printer.new.print(document_from_schema.document)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Union
|
67
|
+
def self.included(klass)
|
68
|
+
klass.extend(HasDirectives)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: graphql-schema_directives
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Greg MacWilliam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: graphql
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: warning
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
description: Schema directives for graphql-ruby
|
84
|
+
email:
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- Gemfile
|
91
|
+
- Gemfile.lock
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- graphql-schema_directives.gemspec
|
96
|
+
- lib/graphql-schema_directives.rb
|
97
|
+
- lib/graphql/schema_directives.rb
|
98
|
+
- lib/graphql/schema_directives/has_directives.rb
|
99
|
+
- lib/graphql/schema_directives/initialize_with_directives.rb
|
100
|
+
- lib/graphql/schema_directives/schema_directives_document_from_schema_definition.rb
|
101
|
+
- lib/graphql/schema_directives/types.rb
|
102
|
+
- lib/graphql/schema_directives/version.rb
|
103
|
+
homepage: https://github.com/gmac/graphql-schema-directives-ruby
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata:
|
107
|
+
homepage_uri: https://github.com/gmac/graphql-schema-directives-ruby
|
108
|
+
changelog_uri: https://github.com/gmac/graphql-schema-directives-ruby/releases
|
109
|
+
source_code_uri: https://github.com/gmac/graphql-schema-directives-ruby
|
110
|
+
bug_tracker_uri: https://github.com/gmac/graphql-schema-directives-ruby/issues
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 2.2.0
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubygems_version: 3.2.3
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Schema directives for graphql-ruby
|
130
|
+
test_files: []
|