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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1db0c5e715fef76694b02bf7886fc6448576ef73aa0e2821dca7e3344843df29
4
- data.tar.gz: 4238d07b94c47897ee083813a1845070c5021749d533eae83715c6e5f1e2397a
3
+ metadata.gz: 443443223656dea1385697579f000561e8b141672b894dc14f2560c4f5bc7d48
4
+ data.tar.gz: 4a8a1532e09704f36d7f5f7a6d8c7c93d87bf231705cf76979a406ffcfcc5b39
5
5
  SHA512:
6
- metadata.gz: 686d0b9cab9be582ab6b83165c25e629013390024607370d9216e3a1f23324d8d3b28c3603af66ddac4854632b5c8058b14456f1c3becc56173a6c1b8e04fc48
7
- data.tar.gz: fcc317f4c19cc3d75f24cf2613d5863c0ef2ac0b8931693ac62941467bc09e245d48bf52b526312d32ac1b2c0ef78fe069f76925757ad83ba6fdd9ced862e2ec
6
+ metadata.gz: a8d1956b33d02a884e43bd7441f00f8962a80435dbd25a9248ad7fc5c4ff2a5e73f904d3c7bc1548232dc1acebb7033149557828a09a370a0ac3194098b2d2f8
7
+ data.tar.gz: acbc49d198bd424b44877a670c3a2847b5e2c5035982cc67b65558a2aaac06baf4a951b8a90d8905390dd7cee0f0c3b1193009db29d7764b5066aed1404fafee
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.5.1
6
+
7
+ * Add the `schema_generation_context?` attribute to the GraphQL `context` when generating the schema.
8
+
5
9
  ## 0.5.0
6
10
 
7
11
  **Breaking Changes**
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.4.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
- - [Rake task](#rake-task)
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
- ### Rake task
125
+ ### Schema Generation
125
126
 
126
- There is a Rake task to generate the `schema.graphql` file. All you need to provide is the path to the old and the new schema files so that the task can detect breaking changes. If you don't have an old schema file because it's your first time generating it then the rake task will just create one for you.
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, context: context)
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
@@ -1,3 +1,3 @@
1
1
  module NulogyGraphqlApi
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -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.9"
32
- spec.add_dependency "graphql-schema_comparator", "~> 0.6.1"
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.0
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-05 00:00:00.000000000 Z
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: '1.9'
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: '1.9'
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.6.1
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.6.1
40
+ version: 1.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement