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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a822ff7b331a58f0e98cdbf01a847d8d517b7ff501ddf463a4e28500e458160
4
- data.tar.gz: cfb2dca848ab0b607c63ab6e2265cd657241b85b3b7a794278d63ebb838bec1d
3
+ metadata.gz: 667ac64c08f68824afa3a9295655e83673e5368f7698183ad2ec915511e07ca7
4
+ data.tar.gz: 47aad12c518ddf7384ec1b72a986d4195e11246780be5f865da50141cd0f6f4b
5
5
  SHA512:
6
- metadata.gz: 977d6690f487260c1950cbf84e26e2d9e58a881cc7de9e7b297e53c99a18afe9d4e57ea51da28593f8ae70f1601d4234bc5df2c78230a6dff58e2deed5a9e94e
7
- data.tar.gz: f8fcb0701baaf9c7177017f5724aacd9b133e9b2120956b29ff0e0d4edd6e2f0c755899a119b8e7f4a3ee789674a59cbb476bff12a7b5a88b5c574f6fcf6f424
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/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
- .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
@@ -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.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 = "3.0.1"
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"
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: 3.0.1
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-01-30 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
@@ -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.5.5
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: []
@@ -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