graphql_devise 1.0.0 → 1.0.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: 79fc4729464c8acabdfc399a6ad2ea777bc411ed1dcbac7e5996c3ea196f603f
4
- data.tar.gz: c45854aec9f2658288170df3ca84aac3910ba3b37a0ecc05c153bd5430e76739
3
+ metadata.gz: 3f82f570616cfaaae35c4660c7f33939bfe749ff615f94c3cd58e6ac7261aec2
4
+ data.tar.gz: 15f4a78b52e3d4ddb9f40343668f983db3eda83dcc4d0f0adda06b4b4394eb98
5
5
  SHA512:
6
- metadata.gz: e7a89e959b02190ac0fd70b0baaa325cbe62e87581b7eed837d95ad5352ab3f8da8c1b5fb165cc0127cdb3e968ec3f9b3634542e511d8ac7f6cde7b81a4b93d5
7
- data.tar.gz: be3ddeedfa069474790a8625478fff36084760c4f00a0810de0c87bc80c67704ed5db0fb8fe293c74a4c16a5a9124cebe75dd61b314d455aec59fa39bed8fd91
6
+ metadata.gz: 7f22e378ecd7d40da887996eafcb77ad83c4fade6cfdfac21ad4200d10c75cfb78f3f98f675052eda164fed451dd703ad23ef3158502b24c974cbabf94e283b9
7
+ data.tar.gz: 2f349211452d275da7fc07337188ff13c8fad04f2577e763a516fd6c43030f2b919bd6d713fb3ef89b2941dc603e600bc0e578df729967db370860bfa43090bf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.0.1](https://github.com/graphql-devise/graphql_devise/tree/v1.0.1) (2022-08-15)
4
+
5
+ [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v1.0.0...v1.0.1)
6
+
7
+ **Fixed bugs:**
8
+
9
+ - A class must be provided when mounting a model. String values are no longer supported [\#235](https://github.com/graphql-devise/graphql_devise/issues/235)
10
+ - Use the class itself in the route generator instead of a string representation [\#236](https://github.com/graphql-devise/graphql_devise/pull/236) ([whotwagner](https://github.com/whotwagner))
11
+ - Honor dta auth cookie when using the schema plugin in a main rails project route [\#233](https://github.com/graphql-devise/graphql_devise/pull/233) ([00dav00](https://github.com/00dav00))
12
+
3
13
  ## [v1.0.0](https://github.com/graphql-devise/graphql_devise/tree/v1.0.0) (2022-08-04)
4
14
 
5
15
  [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.18.2...v1.0.0)
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'zeitwerk'
34
34
 
35
35
  spec.add_development_dependency 'appraisal'
36
- spec.add_development_dependency 'coveralls-ruby', '~> 0.2'
36
+ spec.add_development_dependency 'coveralls_reborn'
37
37
  spec.add_development_dependency 'factory_bot'
38
38
  spec.add_development_dependency 'faker'
39
39
  spec.add_development_dependency 'generator_spec'
@@ -38,7 +38,7 @@ module GraphqlDevise
38
38
  if options['mount'] != 'separate_route'
39
39
  gsub_file(routes_file, /^\s+#{Regexp.escape(dta_route + "\n")}/i, '')
40
40
  else
41
- gem_route = "mount_graphql_devise_for '#{user_class}', at: '#{mount_path}'"
41
+ gem_route = "mount_graphql_devise_for #{user_class}, at: '#{mount_path}'"
42
42
 
43
43
  if file_contains_str?(routes_file, gem_route)
44
44
  gsub_file(routes_file, /^\s+#{Regexp.escape(dta_route + "\n")}/i, '')
@@ -37,7 +37,7 @@ module GraphqlDevise
37
37
 
38
38
  def build_redirect_headers(access_token, client, redirect_header_options = {})
39
39
  {
40
- DeviseTokenAuth.headers_names[:"access-token"] => access_token,
40
+ DeviseTokenAuth.headers_names[:'access-token'] => access_token,
41
41
  DeviseTokenAuth.headers_names[:client] => client,
42
42
  :config => params[:config],
43
43
  :client_id => client,
@@ -66,9 +66,20 @@ module GraphqlDevise
66
66
  end
67
67
  end
68
68
 
69
- def set_auth_headers(resource)
69
+ def generate_auth_headers(resource)
70
70
  auth_headers = resource.create_new_auth_token
71
- response.headers.merge!(auth_headers)
71
+ controller.resource = resource
72
+ access_token_name = DeviseTokenAuth.headers_names[:'access-token']
73
+ client_name = DeviseTokenAuth.headers_names[:'client']
74
+
75
+ # NOTE: Depending on the DTA version, the token will be an object or nil
76
+ if controller.token
77
+ controller.token.client = auth_headers[client_name]
78
+ controller.token.token = auth_headers[access_token_name]
79
+ else
80
+ controller.client_id = auth_headers[client_name]
81
+ controller.token = auth_headers[access_token_name]
82
+ end
72
83
 
73
84
  auth_headers
74
85
  end
@@ -18,7 +18,7 @@ module GraphqlDevise
18
18
 
19
19
  response_payload = { authenticatable: resource }
20
20
 
21
- response_payload[:credentials] = set_auth_headers(resource) if resource.active_for_authentication?
21
+ response_payload[:credentials] = generate_auth_headers(resource) if resource.active_for_authentication?
22
22
 
23
23
  response_payload
24
24
  else
@@ -19,7 +19,7 @@ module GraphqlDevise
19
19
  raise_user_error(I18n.t('graphql_devise.sessions.bad_credentials'))
20
20
  end
21
21
 
22
- new_headers = set_auth_headers(resource)
22
+ new_headers = generate_auth_headers(resource)
23
23
  controller.sign_in(:user, resource, store: false, bypass: false)
24
24
 
25
25
  yield resource if block_given?
@@ -38,7 +38,7 @@ module GraphqlDevise
38
38
 
39
39
  response_payload = { authenticatable: resource }
40
40
 
41
- response_payload[:credentials] = set_auth_headers(resource) if resource.active_for_authentication?
41
+ response_payload[:credentials] = generate_auth_headers(resource) if resource.active_for_authentication?
42
42
 
43
43
  response_payload
44
44
  else
@@ -23,7 +23,7 @@ module GraphqlDevise
23
23
  yield resource if block_given?
24
24
 
25
25
  response_payload = { authenticatable: resource }
26
- response_payload[:credentials] = set_auth_headers(resource) if controller.signed_in?(resource_name)
26
+ response_payload[:credentials] = generate_auth_headers(resource) if controller.signed_in?(resource_name)
27
27
 
28
28
  response_payload
29
29
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlDevise
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -15,7 +15,7 @@ loader = Zeitwerk::Loader.for_gem
15
15
 
16
16
  loader.collapse("#{__dir__}/graphql_devise/concerns")
17
17
  loader.collapse("#{__dir__}/graphql_devise/errors")
18
- loader.collapse("#{__dir__}/generators")
18
+ loader.ignore("#{__dir__}/generators")
19
19
 
20
20
  loader.inflector.inflect('error_codes' => 'ERROR_CODES')
21
21
  loader.inflector.inflect('supported_options' => 'SUPPORTED_OPTIONS')
@@ -4,6 +4,7 @@ module Api
4
4
  module V1
5
5
  class GraphqlController < ApplicationController
6
6
  include GraphqlDevise::SetUserByToken
7
+ include ActionController::Cookies
7
8
 
8
9
  def graphql
9
10
  result = DummySchema.execute(params[:query], **execute_params(params))
@@ -41,7 +41,7 @@ RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
41
41
  let(:args) { [] }
42
42
 
43
43
  it 'creates and updated required files' do
44
- assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'User', at: 'graphql_auth'/
44
+ assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for User, at: 'graphql_auth'/
45
45
  expect(routes_content).not_to match(dta_route)
46
46
 
47
47
  assert_file 'config/initializers/devise.rb'
@@ -60,7 +60,7 @@ RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
60
60
  let(:args) { %w[Admin api] }
61
61
 
62
62
  it 'creates and updated required files' do
63
- assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for 'Admin', at: 'api'/
63
+ assert_file 'config/routes.rb', /^\s{2}mount_graphql_devise_for Admin, at: 'api'/
64
64
  expect(routes_content).not_to match(dta_route)
65
65
 
66
66
  assert_file 'config/initializers/devise.rb'
@@ -184,4 +184,38 @@ RSpec.describe 'Login Requests' do
184
184
  )
185
185
  end
186
186
  end
187
+
188
+
189
+ if DeviseTokenAuth.respond_to?(:cookie_enabled)
190
+ context 'when using cookies for auth' do
191
+ let!(:user) { create(:user, :confirmed, password: password, email: 'vvega@wallaceinc.com') }
192
+ let(:email) { user.email }
193
+ let(:query) do
194
+ <<-GRAPHQL
195
+ mutation {
196
+ userLogin(
197
+ email: "#{email}",
198
+ password: "#{password}"
199
+ ) {
200
+ authenticatable { email }
201
+ credentials { accessToken uid tokenType client expiry }
202
+ }
203
+ }
204
+ GRAPHQL
205
+ end
206
+
207
+ around do |example|
208
+ DeviseTokenAuth.cookie_enabled = true
209
+ example.run
210
+ DeviseTokenAuth.cookie_enabled = false
211
+ end
212
+
213
+ before { post_request('/api/v1/graphql') }
214
+
215
+ it 'honors DTA configuration of setting auth info in cookies' do
216
+ cookie = cookies.get_cookie('auth_cookie')
217
+ expect(JSON.parse(cookie.value).keys).to include(*%w[uid access-token client])
218
+ end
219
+ end
220
+ end
187
221
  end
@@ -91,5 +91,44 @@ RSpec.describe GraphqlDevise::ResourceLoader do
91
91
  end
92
92
  end
93
93
  end
94
+
95
+ context 'when argument errors are raised when field is set' do
96
+ context 'when mutation raises an argument error' do
97
+ before { allow(mutation).to receive(:field).and_raise(ArgumentError, 'mutation error') }
98
+
99
+ if Gem::Version.new(GraphQL::VERSION) < Gem::Version.new('2.0')
100
+ it 'raises the same argument error' do
101
+ expect { loader }.to raise_error(
102
+ ArgumentError,
103
+ 'mutation error'
104
+ )
105
+ end
106
+ else
107
+ it 'raises a GraphqlDevise::Error error' do
108
+ expect { loader }.to raise_error(GraphqlDevise::Error)
109
+ end
110
+ end
111
+ end
112
+
113
+ context 'when query raises an argument error' do
114
+ before do
115
+ allow(mutation).to receive(:field)
116
+ allow(query).to receive(:field).and_raise(ArgumentError, 'query error')
117
+ end
118
+
119
+ if Gem::Version.new(GraphQL::VERSION) < Gem::Version.new('2.0')
120
+ it 'raises the same argument error' do
121
+ expect { loader }.to raise_error(
122
+ ArgumentError,
123
+ 'query error'
124
+ )
125
+ end
126
+ else
127
+ it 'raises a GraphqlDevise::Error error' do
128
+ expect { loader }.to raise_error(GraphqlDevise::Error)
129
+ end
130
+ end
131
+ end
132
+ end
94
133
  end
95
134
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if ENV['CI'] && !ENV['SKIP_COVERALLS']
3
+ if ENV['CI'] && !ENV['SKIP_COVERALLS'] && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5')
4
4
  require 'simplecov'
5
5
  require 'coveralls'
6
6
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_devise
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Celi
8
8
  - David Revelo
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-08-04 00:00:00.000000000 Z
12
+ date: 2022-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: devise_token_auth
@@ -100,19 +100,19 @@ dependencies:
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  - !ruby/object:Gem::Dependency
103
- name: coveralls-ruby
103
+ name: coveralls_reborn
104
104
  requirement: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - "~>"
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
- version: '0.2'
108
+ version: '0'
109
109
  type: :development
110
110
  prerelease: false
111
111
  version_requirements: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: '0.2'
115
+ version: '0'
116
116
  - !ruby/object:Gem::Dependency
117
117
  name: factory_bot
118
118
  requirement: !ruby/object:Gem::Requirement
@@ -511,7 +511,7 @@ licenses:
511
511
  metadata:
512
512
  homepage_uri: https://github.com/graphql-devise/graphql_devise
513
513
  source_code_uri: https://github.com/graphql-devise/graphql_devise
514
- post_install_message:
514
+ post_install_message:
515
515
  rdoc_options: []
516
516
  require_paths:
517
517
  - lib
@@ -526,8 +526,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
526
526
  - !ruby/object:Gem::Version
527
527
  version: '0'
528
528
  requirements: []
529
- rubygems_version: 3.3.19
530
- signing_key:
529
+ rubygems_version: 3.1.6
530
+ signing_key:
531
531
  specification_version: 4
532
532
  summary: GraphQL queries and mutations on top of devise_token_auth
533
533
  test_files: