nulogy_graphql_api 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +45 -12
- data/lib/nulogy_graphql_api/tasks/schema_generator.rb +3 -1
- data/lib/nulogy_graphql_api/version.rb +1 -1
- data/nulogy_graphql_api.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 443443223656dea1385697579f000561e8b141672b894dc14f2560c4f5bc7d48
|
4
|
+
data.tar.gz: 4a8a1532e09704f36d7f5f7a6d8c7c93d87bf231705cf76979a406ffcfcc5b39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8d1956b33d02a884e43bd7441f00f8962a80435dbd25a9248ad7fc5c4ff2a5e73f904d3c7bc1548232dc1acebb7033149557828a09a370a0ac3194098b2d2f8
|
7
|
+
data.tar.gz: acbc49d198bd424b44877a670c3a2847b5e2c5035982cc67b65558a2aaac06baf4a951b8a90d8905390dd7cee0f0c3b1193009db29d7764b5066aed1404fafee
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
Add this line to your application's Gemfile:
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem "nulogy_graphql_api", "0.
|
8
|
+
gem "nulogy_graphql_api", "0.5.1"
|
9
9
|
```
|
10
10
|
|
11
11
|
And then execute:
|
@@ -25,7 +25,8 @@ Or install it yourself as:
|
|
25
25
|
- [Types](#types)
|
26
26
|
- [UserErrorType](#usererrortype)
|
27
27
|
- [UUID](#uuid)
|
28
|
-
- [
|
28
|
+
- [Schema Generation](#schema-generation)
|
29
|
+
- [Node Visibility](#node-visibility)
|
29
30
|
|
30
31
|
#### Testing
|
31
32
|
|
@@ -121,9 +122,11 @@ module MyApp
|
|
121
122
|
end
|
122
123
|
```
|
123
124
|
|
124
|
-
###
|
125
|
+
### Schema Generation
|
125
126
|
|
126
|
-
There is a Rake task to generate the `schema.graphql` file.
|
127
|
+
There is a Rake task to generate the `schema.graphql` file. You need to provide the `schema_file_path` and the `schema_definition_path` so that the task can detect breaking changes and generate the file. If you don't have a schema file because it's your first time generating it then the rake task will just create one for you in the path provided.
|
128
|
+
|
129
|
+
There is also a third argument `context`. You'll have to configure it to be able to generate the SDL of fields or types that are only visible for more privileged users.
|
127
130
|
|
128
131
|
```ruby
|
129
132
|
namespace :graphql_api do
|
@@ -133,20 +136,50 @@ namespace :graphql_api do
|
|
133
136
|
schema_file_path = MyApp::Engine.root.join("schema.graphql")
|
134
137
|
schema_definition_path = MyApp::Engine.root.join("path/to/schema/root/schema.rb")
|
135
138
|
|
136
|
-
# Context is an optional parameter, but may be required if you change the visibility of nodes in your graph
|
137
|
-
# i.e.
|
138
|
-
# def visible?(context)
|
139
|
-
# context[:current_user].superuser?
|
140
|
-
# end
|
141
|
-
context = {}
|
142
|
-
|
143
139
|
NulogyGraphqlApi::Tasks::SchemaGenerator
|
144
|
-
.new(schema_file_path, schema_definition_path
|
140
|
+
.new(schema_file_path, schema_definition_path)
|
145
141
|
.generate_schema
|
146
142
|
end
|
147
143
|
end
|
148
144
|
```
|
149
145
|
|
146
|
+
### Node visibility
|
147
|
+
|
148
|
+
When you customize the visibility of parts of your graph you have to make sure that node will be visible when the schema is being generated. You can do so by using the `schema_generation_context?` attribute that is added to the context by the `SchemaGenerator` mentioned in the previous section.
|
149
|
+
|
150
|
+
Here is how to use it:
|
151
|
+
|
152
|
+
##### For fields
|
153
|
+
```ruby
|
154
|
+
field :entity, MyApp::EntityType, null: false do
|
155
|
+
description "Find an entity by ID"
|
156
|
+
argument :id, ID, required: true
|
157
|
+
|
158
|
+
def visible?(context)
|
159
|
+
context[:schema_generation_context?] || context[:current_user].superuser?
|
160
|
+
end
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
|
165
|
+
##### For classes
|
166
|
+
```ruby
|
167
|
+
module MyApp
|
168
|
+
class CreateEntity < GraphQL::Schema::Mutation
|
169
|
+
field :entity, MyApp::EntityType, null: false
|
170
|
+
field :errors, [NulogyGraphqlApi::Types::UserErrorType], null: false
|
171
|
+
|
172
|
+
def self.visible(context)
|
173
|
+
super && (context[:schema_generation_context?] || context[:current_user].superuser?)
|
174
|
+
end
|
175
|
+
|
176
|
+
def resolve(args)
|
177
|
+
# ...
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
150
183
|
### RSpec helpers
|
151
184
|
|
152
185
|
Add this to your `spec_helpers.rb` file:
|
@@ -4,7 +4,9 @@ module NulogyGraphqlApi
|
|
4
4
|
def initialize(schema_output_path, schema_definition_path, context: {})
|
5
5
|
@schema_output_path = schema_output_path
|
6
6
|
@schema_definition_path = schema_definition_path
|
7
|
-
@context = context
|
7
|
+
@context = context.merge(
|
8
|
+
schema_generation_context?: true
|
9
|
+
)
|
8
10
|
end
|
9
11
|
|
10
12
|
def generate_schema
|
data/nulogy_graphql_api.gemspec
CHANGED
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
-
spec.add_dependency "graphql", "~> 1.
|
32
|
-
spec.add_dependency "graphql-schema_comparator", "~> 0.
|
31
|
+
spec.add_dependency "graphql", "~> 1.11.2"
|
32
|
+
spec.add_dependency "graphql-schema_comparator", "~> 1.0.0"
|
33
33
|
spec.add_dependency "rails", ">= 5.2.4", "< 6.1.0"
|
34
34
|
spec.add_dependency "rainbow", "~> 3.0.0"
|
35
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nulogy_graphql_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.11.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.11.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: graphql-schema_comparator
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 1.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 1.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|