nulogy_graphql_api 3.0.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +17 -0
- data/README.md +2 -44
- data/lib/nulogy_graphql_api/rspec/graphql_helpers.rb +4 -2
- data/lib/nulogy_graphql_api/tasks/schema_generator.rb +12 -17
- data/lib/nulogy_graphql_api/version.rb +1 -1
- data/lib/nulogy_graphql_api.rb +0 -1
- metadata +7 -8
- data/lib/nulogy_graphql_api/schema/base_mutation.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 667ac64c08f68824afa3a9295655e83673e5368f7698183ad2ec915511e07ca7
|
4
|
+
data.tar.gz: 47aad12c518ddf7384ec1b72a986d4195e11246780be5f865da50141cd0f6f4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9198a3f63dba4a251caa0c271f118d14aa517ad0f76c89f0398459a8c98b513bb994930fd998016d9d980700db8ff3a2e995549b6eda4d7e30648c5c87f84cd
|
7
|
+
data.tar.gz: e55542aad8ed580489783ea890914304e4a98e4f02a7518d6689038977fdeefae3618b927a84486157bb1f057f6680da0c78000394724c97e6c408ed54844615
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,23 @@
|
|
4
4
|
|
5
5
|
_none_
|
6
6
|
|
7
|
+
## 4.0.0 (2024-05-28)
|
8
|
+
|
9
|
+
**Changes**
|
10
|
+
|
11
|
+
* Remove the `schema_generation_context?` attribute to the GraphQL `context` when generating the schema. Use the
|
12
|
+
already available `GraphQL::Schema::AlwaysVisible` plugin instead.
|
13
|
+
* **(Breaking)** Remove the `NulogyGraphqlApi::Schema::BaseMutation` class which introduced a new API for the
|
14
|
+
`visible?` method that took a block. This introduced a deviation from the ruby graphql gem's API only for
|
15
|
+
Mutations and so it was removed. Please ensure that any invocations of `visible?` do not take a block and use
|
16
|
+
`GraphQL::Schema::Mutation` instead.
|
17
|
+
* **(Breaking)** Change the `NulogyGraphqlApi::Tasks::SchemaGenerator#generate_schema` method to output the
|
18
|
+
stringified version of the schema instead of checking it for changes and writing it to a file.
|
19
|
+
* Expose the `#check_changes` and `#write_schema_to_file` methods on the
|
20
|
+
`NulogyGraphqlApi::Tasks::SchemaGenerator` to give the user more control over how to build their
|
21
|
+
tooling.
|
22
|
+
* Allow the user to be specified for the `request_graphql` test helper.
|
23
|
+
|
7
24
|
## 3.0.1 (2024-01-30)
|
8
25
|
|
9
26
|
* Add `include_graphql_error` RSpec matcher
|
data/README.md
CHANGED
@@ -130,8 +130,6 @@ end
|
|
130
130
|
|
131
131
|
There is a Rake task to generate the `schema.graphql` file. You need to provide the `schema_file_path` and the schema class 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.
|
132
132
|
|
133
|
-
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.
|
134
|
-
|
135
133
|
```ruby
|
136
134
|
namespace :graphql_api do
|
137
135
|
desc "Generate the graphql schema of the api."
|
@@ -142,47 +140,7 @@ namespace :graphql_api do
|
|
142
140
|
|
143
141
|
NulogyGraphqlApi::Tasks::SchemaGenerator
|
144
142
|
.new(schema_file_path, schema)
|
145
|
-
.
|
146
|
-
end
|
147
|
-
end
|
148
|
-
```
|
149
|
-
|
150
|
-
### Node visibility
|
151
|
-
|
152
|
-
When you customize the visibility of parts of your graph you have to make sure that all nodes are visible when the schema is being generated by the rake task. 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.
|
153
|
-
|
154
|
-
Here is how to use it:
|
155
|
-
|
156
|
-
##### On fields
|
157
|
-
```ruby
|
158
|
-
field :entity, MyApp::EntityType, null: false do
|
159
|
-
description "Find an entity by ID"
|
160
|
-
argument :id, ID, required: true
|
161
|
-
|
162
|
-
def visible?(context)
|
163
|
-
context[:schema_generation_context?] || context[:current_user].superuser?
|
164
|
-
end
|
165
|
-
end
|
166
|
-
```
|
167
|
-
|
168
|
-
|
169
|
-
##### On mutations
|
170
|
-
|
171
|
-
In this case the `schema_generation_context?` attribute is checked by the `BaseMutation` class. All you have to do is inheriting from it and override `visible?` passing a block to the base method.
|
172
|
-
|
173
|
-
```ruby
|
174
|
-
module MyApp
|
175
|
-
class CreateEntity < NulogyGraphqlApi::Schema::BaseMutation
|
176
|
-
field :entity, MyApp::EntityType, null: false
|
177
|
-
field :errors, [NulogyGraphqlApi::Types::UserErrorType], null: false
|
178
|
-
|
179
|
-
def self.visible?(context)
|
180
|
-
super { context[:current_user].super_user? }
|
181
|
-
end
|
182
|
-
|
183
|
-
def resolve(args)
|
184
|
-
# ...
|
185
|
-
end
|
143
|
+
.write_schema_to_file
|
186
144
|
end
|
187
145
|
end
|
188
146
|
```
|
@@ -237,7 +195,7 @@ The `request_graphql` helper issues a POST request against the provided URL. Thi
|
|
237
195
|
```ruby
|
238
196
|
RSpec.describe MyApp::Graphql::Query, :graphql, type: :request do
|
239
197
|
it "returns 401 Unauthorized given an unauthenticated request" do
|
240
|
-
gql_response = request_graphql(url, <<~GRAPHQL, headers: { "HTTP_AUTHORIZATION" => nil })
|
198
|
+
gql_response = request_graphql(url, <<~GRAPHQL, headers: { "HTTP_AUTHORIZATION" => nil }, user: default_user)
|
241
199
|
query {
|
242
200
|
entities {
|
243
201
|
id
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module NulogyGraphqlApi
|
2
2
|
module GraphqlHelpers
|
3
|
+
# Prefer the `request_graphql` method over this one because it exercises more of the stack but doesn't run
|
4
|
+
# much slower.
|
3
5
|
def execute_graphql(query, schema, variables: {}, context: {})
|
4
6
|
camelized_variables = variables.deep_transform_keys! { |key| key.to_s.camelize(:lower) } || {}
|
5
7
|
|
@@ -13,11 +15,11 @@ module NulogyGraphqlApi
|
|
13
15
|
response.to_h.deep_symbolize_keys
|
14
16
|
end
|
15
17
|
|
16
|
-
def request_graphql(url, query, variables: {}, headers: {})
|
18
|
+
def request_graphql(url, query, variables: {}, headers: {}, user: nil)
|
17
19
|
params = { query: query, variables: variables }.to_json
|
18
20
|
default_headers = {
|
19
21
|
CONTENT_TYPE: "application/json",
|
20
|
-
HTTP_AUTHORIZATION: basic_auth_token(default_user.login)
|
22
|
+
HTTP_AUTHORIZATION: basic_auth_token((user || default_user).login)
|
21
23
|
}
|
22
24
|
|
23
25
|
post url, params: params, headers: default_headers.merge(headers)
|
@@ -4,37 +4,32 @@ module NulogyGraphqlApi
|
|
4
4
|
def initialize(schema_output_path, schema, context: {})
|
5
5
|
@schema_output_path = schema_output_path
|
6
6
|
@schema = schema
|
7
|
-
@context = context
|
8
|
-
schema_generation_context?: true
|
9
|
-
)
|
7
|
+
@context = context
|
10
8
|
end
|
11
9
|
|
12
10
|
def generate_schema
|
13
|
-
|
14
|
-
|
11
|
+
visible_schema = Class.new(@schema)
|
12
|
+
visible_schema.use(GraphQL::Schema::AlwaysVisible)
|
13
|
+
visible_schema.to_definition(context: @context)
|
15
14
|
end
|
16
15
|
|
17
|
-
private
|
18
|
-
|
19
16
|
def check_changes
|
20
17
|
return if old_schema.blank?
|
21
18
|
|
22
|
-
SchemaChangesChecker.new.check_changes(old_schema,
|
23
|
-
end
|
24
|
-
|
25
|
-
def old_schema
|
26
|
-
return unless File.exist?(@schema_output_path)
|
27
|
-
|
28
|
-
File.read(@schema_output_path)
|
19
|
+
SchemaChangesChecker.new.check_changes(old_schema, generate_schema)
|
29
20
|
end
|
30
21
|
|
31
22
|
def write_schema_to_file
|
32
|
-
File.write(@schema_output_path,
|
23
|
+
File.write(@schema_output_path, generate_schema)
|
33
24
|
puts Rainbow("\nSuccessfully updated #{@schema_output_path}").green
|
34
25
|
end
|
35
26
|
|
36
|
-
|
37
|
-
|
27
|
+
private
|
28
|
+
|
29
|
+
def old_schema
|
30
|
+
return unless File.exist?(@schema_output_path)
|
31
|
+
|
32
|
+
File.read(@schema_output_path)
|
38
33
|
end
|
39
34
|
end
|
40
35
|
end
|
data/lib/nulogy_graphql_api.rb
CHANGED
@@ -3,7 +3,6 @@ require "graphql"
|
|
3
3
|
require "nulogy_graphql_api/error_handling"
|
4
4
|
require "nulogy_graphql_api/graphql_executor"
|
5
5
|
require "nulogy_graphql_api/graphql_response"
|
6
|
-
require "nulogy_graphql_api/schema/base_mutation"
|
7
6
|
require "nulogy_graphql_api/transaction_service"
|
8
7
|
require "nulogy_graphql_api/tasks/schema_changes_checker"
|
9
8
|
require "nulogy_graphql_api/tasks/schema_generator"
|
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Silva
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -198,7 +198,7 @@ dependencies:
|
|
198
198
|
- - "~>"
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '1.4'
|
201
|
-
description:
|
201
|
+
description:
|
202
202
|
email:
|
203
203
|
- danielsi@nulogy.com
|
204
204
|
executables: []
|
@@ -234,7 +234,6 @@ files:
|
|
234
234
|
- lib/nulogy_graphql_api/rspec.rb
|
235
235
|
- lib/nulogy_graphql_api/rspec/graphql_helpers.rb
|
236
236
|
- lib/nulogy_graphql_api/rspec/graphql_matchers.rb
|
237
|
-
- lib/nulogy_graphql_api/schema/base_mutation.rb
|
238
237
|
- lib/nulogy_graphql_api/tasks/schema_changes_checker.rb
|
239
238
|
- lib/nulogy_graphql_api/tasks/schema_generator.rb
|
240
239
|
- lib/nulogy_graphql_api/transaction_service.rb
|
@@ -252,7 +251,7 @@ metadata:
|
|
252
251
|
source_code_uri: https://github.com/nulogy/nulogy_graphql_api
|
253
252
|
bug_tracker_uri: https://github.com/nulogy/nulogy_graphql_api/issues
|
254
253
|
rubygems_mfa_required: 'true'
|
255
|
-
post_install_message:
|
254
|
+
post_install_message:
|
256
255
|
rdoc_options: []
|
257
256
|
require_paths:
|
258
257
|
- lib
|
@@ -267,8 +266,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
266
|
- !ruby/object:Gem::Version
|
268
267
|
version: '0'
|
269
268
|
requirements: []
|
270
|
-
rubygems_version: 3.
|
271
|
-
signing_key:
|
269
|
+
rubygems_version: 3.3.26
|
270
|
+
signing_key:
|
272
271
|
specification_version: 4
|
273
272
|
summary: Standard tooling for building GraphQL apis
|
274
273
|
test_files: []
|