nulogy_graphql_api 2.2.0 → 4.0.0

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: e3ef0420e5eced452c468681a47db0bf23f28066a1a8db5b71f264a82a752db3
4
- data.tar.gz: 2f6e5aacd8a918f3e5c23502180999e049e434171b20dff3c01187ef14dfa870
3
+ metadata.gz: 667ac64c08f68824afa3a9295655e83673e5368f7698183ad2ec915511e07ca7
4
+ data.tar.gz: 47aad12c518ddf7384ec1b72a986d4195e11246780be5f865da50141cd0f6f4b
5
5
  SHA512:
6
- metadata.gz: eb98d61ac93b589baf8c914c4e8b6cf9021d8a71b69b97474b44566da92b9a9b33a98df877801f9d847658900e63864185d13f69b0eb7454bf59613c83dc6081
7
- data.tar.gz: 22827e08ec2ea12acc34048d5bd892b7d95bcdf2a277b93b9a625e87ed9e56a70dab2bb6ca4e5875ad124a951c33088bd8605aac505bfdcff9d7be93e010764b
6
+ metadata.gz: d9198a3f63dba4a251caa0c271f118d14aa517ad0f76c89f0398459a8c98b513bb994930fd998016d9d980700db8ff3a2e995549b6eda4d7e30648c5c87f84cd
7
+ data.tar.gz: e55542aad8ed580489783ea890914304e4a98e4f02a7518d6689038977fdeefae3618b927a84486157bb1f057f6680da0c78000394724c97e6c408ed54844615
data/.gitignore CHANGED
@@ -7,6 +7,8 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /spec/dummy/tmp/local_secret.txt
11
+ /spec/dummy/db/test.sqlite3*
10
12
 
11
13
  # rspec failure tracking
12
14
  .rspec_status
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.4
1
+ 3.1.4
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.1.4
data/Appraisals CHANGED
@@ -1,7 +1,3 @@
1
- appraise "rails-6" do
2
- gem "rails", "6.0.3.7"
3
- end
4
-
5
1
  appraise "rails-6-1" do
6
2
  gem "rails", "6.1.4"
7
3
  end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,33 @@
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
+
24
+ ## 3.0.1 (2024-01-30)
25
+
26
+ * Add `include_graphql_error` RSpec matcher
27
+
28
+ ## 3.0.0 (2024-01-30)
29
+
30
+ **Changes**
31
+ * **(Breaking)** Drop support for Rails 6.0
32
+ * **(Breaking)** Drop support for Ruby 2.7
33
+
7
34
  ## 2.2.0 (2024-01-15)
8
35
 
9
36
  **Changes**
data/README.md CHANGED
@@ -9,7 +9,7 @@ Help Nulogy applications be compliant with the [Standard on Error-handling in Gr
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem "nulogy_graphql_api", "2.1.0"
12
+ gem "nulogy_graphql_api", "3.0.1"
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -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
- .generate_schema
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
@@ -253,9 +211,7 @@ end
253
211
 
254
212
  #### Custom matchers
255
213
 
256
- These are the custom matchers available:
257
-
258
- `have_graphql_data` for checking the response `data`
214
+ Use `have_graphql_data` for checking the response `data`.
259
215
 
260
216
  ```ruby
261
217
  expect(response).to have_graphql_data(
@@ -265,12 +221,20 @@ expect(response).to have_graphql_data(
265
221
  )
266
222
  ```
267
223
 
268
- `have_graphql_error` for checking the response `errors`
224
+ Use `have_graphql_error` for matching exactly on the response `errors`. <br/>
225
+ The match succeeds when the `errors` array contains a single entry with the specified message.
269
226
 
270
227
  ```ruby
271
228
  expect(response).to have_graphql_error("Error message")
272
229
  ```
273
230
 
231
+ Use `include_graphql_error` for matching inclusively on the response `errors`. <br/>
232
+ The match succeeds when the `errors` array includes an entry with the specified message.
233
+
234
+ ```ruby
235
+ expect(response).to include_graphql_error("Error message")
236
+ ```
237
+
274
238
  ## Development
275
239
 
276
240
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -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)
@@ -34,5 +34,13 @@ module NulogyGraphqlApi
34
34
  })
35
35
  end
36
36
  end
37
+
38
+ RSpec::Matchers.define :include_graphql_error do |message|
39
+ match do |actual_response|
40
+ expect(actual_response.fetch(:errors, nil)).to include(a_hash_including(
41
+ message: include(message)
42
+ ))
43
+ end
44
+ end
37
45
  end
38
46
  end
@@ -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.merge(
8
- schema_generation_context?: true
9
- )
7
+ @context = context
10
8
  end
11
9
 
12
10
  def generate_schema
13
- check_changes
14
- write_schema_to_file
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, @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, schema_definition)
23
+ File.write(@schema_output_path, generate_schema)
33
24
  puts Rainbow("\nSuccessfully updated #{@schema_output_path}").green
34
25
  end
35
26
 
36
- def schema_definition
37
- GraphQL::Schema::Printer.print_schema(@schema, context: @context)
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
@@ -1,3 +1,3 @@
1
1
  module NulogyGraphqlApi
2
- VERSION = "2.2.0"
2
+ VERSION = "4.0.0"
3
3
  end
@@ -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"
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  "rubygems_mfa_required" => "true"
19
19
  }
20
20
 
21
- spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
21
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_dependency "graphql", "~> 2"
33
33
  spec.add_dependency "graphql-schema_comparator", "~> 1.2"
34
- spec.add_dependency "rails", ">= 6.0", "< 8.0"
34
+ spec.add_dependency "rails", ">= 6.1", "< 8.0"
35
35
  spec.add_dependency "rainbow", "~> 3.0"
36
36
 
37
37
  spec.add_development_dependency "appraisal", "~> 2.5"
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: 2.2.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-15 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -44,7 +44,7 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '6.0'
47
+ version: '6.1'
48
48
  - - "<"
49
49
  - !ruby/object:Gem::Version
50
50
  version: '8.0'
@@ -54,7 +54,7 @@ dependencies:
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: '6.0'
57
+ version: '6.1'
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '8.0'
@@ -213,6 +213,7 @@ files:
213
213
  - ".rubocop.directories.yml"
214
214
  - ".rubocop.yml"
215
215
  - ".ruby-version"
216
+ - ".tool-versions"
216
217
  - Appraisals
217
218
  - CHANGELOG.md
218
219
  - CODE_OF_CONDUCT.md
@@ -222,7 +223,6 @@ files:
222
223
  - Rakefile
223
224
  - bin/console
224
225
  - bin/setup
225
- - gemfiles/rails_6.gemfile
226
226
  - gemfiles/rails_6_1.gemfile
227
227
  - gemfiles/rails_7.gemfile
228
228
  - lib/nulogy_graphql_api.rb
@@ -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
@@ -260,14 +259,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
260
259
  requirements:
261
260
  - - ">="
262
261
  - !ruby/object:Gem::Version
263
- version: 2.6.0
262
+ version: 3.0.0
264
263
  required_rubygems_version: !ruby/object:Gem::Requirement
265
264
  requirements:
266
265
  - - ">="
267
266
  - !ruby/object:Gem::Version
268
267
  version: '0'
269
268
  requirements: []
270
- rubygems_version: 3.1.6
269
+ rubygems_version: 3.3.26
271
270
  signing_key:
272
271
  specification_version: 4
273
272
  summary: Standard tooling for building GraphQL apis
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "6.0.3.7"
6
-
7
- gemspec path: "../"
@@ -1,12 +0,0 @@
1
- module NulogyGraphqlApi
2
- module Schema
3
- class BaseMutation < GraphQL::Schema::Mutation
4
- def self.visible?(context)
5
- return true if context[:schema_generation_context?]
6
- return super && yield if block_given?
7
-
8
- super
9
- end
10
- end
11
- end
12
- end