graphql_devise 0.9.2 → 0.10.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: fe858d6f23e94afcd3ceda214e226c481be42610c562ce2c409ce0146ba930b3
4
- data.tar.gz: bb1252da47c939b6d8643975847acc57f3ae7a2abd4edf1d30717f0f0f1dce3d
3
+ metadata.gz: 33e021f456447d0a8d0c17ec98f365337b2d41427b5aac9cb521313317752fd4
4
+ data.tar.gz: 9aebe3c7d5e0c389a7e329ca6a703b56d936464a8b20c1c2003798667309a886
5
5
  SHA512:
6
- metadata.gz: a26de357c7dc92c7326e1251fd920704359fe15b72841d8db4a2903cc74291023b8614e0fff99a3d6a99c65c73dbba70c805033d91967a8684108e170d46ca4a
7
- data.tar.gz: 37576fd86f5921201be2b694fe83b55746949e4d79bc08e9b08dc0f753fec43709f344667c5a5ec73a0f8e07b956cb9fce968d97f211949cde4f09b18fc38d82
6
+ metadata.gz: c31ce514a8ab6f68e0501ed0b9435b183ced05433894ecc2214783a6027d48953a00b26234ccfbbf767d76766266329a81c3a296320cbdf3efe939b408682160
7
+ data.tar.gz: eff949b9be0f805b9b89da5b917863a76a27ff3cc992e2162286f1ab6162c5dc2324a19cf8df87e46ed15cb78a511fb0957a3a9aba986f0bb7cb60d14c9de316
data/.travis.yml CHANGED
@@ -36,12 +36,19 @@ jobs:
36
36
  rvm: 2.5.7
37
37
  - gemfile: gemfiles/rails6.0_graphql1.10.gemfile
38
38
  rvm: 2.6.5
39
- - gemfile: gemfiles/rails_edge_graphql_edge.gemfile
39
+ - gemfile: gemfiles/rails6.0_graphql_edge.gemfile
40
40
  rvm: 2.5.7
41
+ env: SKIP_COVERALLS=true
42
+ - gemfile: gemfiles/rails6.0_graphql_edge.gemfile
43
+ rvm: 2.6.5
44
+ env: SKIP_COVERALLS=true
41
45
  - gemfile: gemfiles/rails_edge_graphql_edge.gemfile
42
46
  rvm: 2.6.5
47
+ env: SKIP_COVERALLS=true
43
48
  allow_failures:
44
49
  - rvm: 2.5.7
45
- gemfile: gemfiles/rails_edge_graphql_edge.gemfile
50
+ gemfile: gemfiles/rails6.0_graphql_edge.gemfile
51
+ - rvm: 2.6.5
52
+ gemfile: gemfiles/rails6.0_graphql_edge.gemfile
46
53
  - rvm: 2.6.5
47
54
  gemfile: gemfiles/rails_edge_graphql_edge.gemfile
data/Appraisals CHANGED
@@ -74,6 +74,14 @@ appraise 'rails6.0-graphql1.10' do
74
74
  gem 'graphql', '~> 1.10.0'
75
75
  end
76
76
 
77
+ appraise 'rails6.0-graphql_edge' do
78
+ gem 'sqlite3', '~> 1.4'
79
+ gem 'devise_token_auth', github: 'lynndylanhurley/devise_token_auth', branch: 'master'
80
+ gem 'devise', '>= 4.7'
81
+ gem 'rails', github: 'rails/rails', branch: '6-0-stable'
82
+ gem 'graphql', github: 'rmosolgo/graphql-ruby', branch: 'master'
83
+ end
84
+
77
85
  appraise 'rails_edge-graphql_edge' do
78
86
  gem 'sqlite3', '~> 1.4'
79
87
  gem 'devise_token_auth', github: 'lynndylanhurley/devise_token_auth', branch: 'master'
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## [v0.9.2](https://github.com/graphql-devise/graphql_devise/tree/v0.9.2) (2020-02-03)
3
+ ## [v0.10.0](https://github.com/graphql-devise/graphql_devise/tree/v0.10.0) (2020-02-04)
4
+
5
+ [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.9.2...v0.10.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Add additional mutations and queries option [\#64](https://github.com/graphql-devise/graphql_devise/pull/64) ([mcelicalderon](https://github.com/mcelicalderon))
10
+
11
+ ## [v0.9.2](https://github.com/graphql-devise/graphql_devise/tree/v0.9.2) (2020-02-02)
4
12
 
5
13
  [Full Changelog](https://github.com/graphql-devise/graphql_devise/compare/v0.9.1...v0.9.2)
6
14
 
data/README.md CHANGED
@@ -46,7 +46,7 @@ Will do the following:
46
46
  - Add `devise` modules to `Admin` model
47
47
  - Other changes that you can find [here](https://devise-token-auth.gitbook.io/devise-token-auth/config)
48
48
  - Add the route to `config/routes.rb`
49
- - `mount_graphql_devise_for 'Admin', at: 'api/auth'
49
+ - `mount_graphql_devise_for 'Admin', at: 'api/auth'`
50
50
 
51
51
  `Admin` could be any model name you are going to be using for authentication,
52
52
  and `api/auth` could be any mount path you would like to use for auth.
@@ -66,7 +66,15 @@ Rails.application.routes.draw do
66
66
  operations: {
67
67
  login: Mutations::Login
68
68
  },
69
- skip: [:sign_up]
69
+ skip: [:sign_up],
70
+ additional_mutations: {
71
+ # generates mutation { adminUserSignUp }
72
+ admin_user_sign_up: Mutations::AdminUserSignUp
73
+ },
74
+ additional_queries: {
75
+ # generates query { publicUserByUuid }
76
+ public_user_by_uuid: Resolvers::UserByUuid
77
+ }
70
78
  )
71
79
  end
72
80
  ```
@@ -90,6 +98,28 @@ will use it. But, you can override this type with this option like in the exampl
90
98
  symbols and should belong to the list of available operations in the gem.
91
99
  1. `only`: An array of the operations that should be available in the authentication schema. The `skip` and `only` options are
92
100
  mutually exclusive, an error will be raised if you pass both to the mount method.
101
+ 1. `additional_mutations`: Here you can add as many mutations as you
102
+ need, for those features that don't fully match the provided default mutations and queries.
103
+ You need to provide a hash to this option, and
104
+ each key will be the name of the mutation on the schema. Also, the value provided must be a valid mutation.
105
+ This is similar to what you can accomplish with
106
+ [devise_scope](https://www.rubydoc.info/github/heartcombo/devise/master/ActionDispatch/Routing/Mapper%3Adevise_for).
107
+ 1. `additional_queries`: Here you can add as many queries as you need,
108
+ for those features that don't fully match the provided default mutations and queries.
109
+ You need to provide a hash to this option, and
110
+ each key will be the name of the query on the schema. Also, the value provided must be a valid Resolver.
111
+ This is also similar to what you can accomplish with
112
+ [devise_scope](https://www.rubydoc.info/github/heartcombo/devise/master/ActionDispatch/Routing/Mapper%3Adevise_for).
113
+
114
+ Additional mutations and queries will be added to the schema regardless
115
+ of other options you might have specified like `skip` or `only`.
116
+ Additional queries and mutations is usually a good place for other
117
+ operations on your schema that require no authentication (like sign_up).
118
+ Also by adding them through the mount method, your mutations and
119
+ resolvers can inherit from our [base mutation](https://github.com/graphql-devise/graphql_devise/blob/master/app/graphql/graphql_devise/mutations/base.rb)
120
+ or [base resover](https://github.com/graphql-devise/graphql_devise/blob/master/app/graphql/graphql_devise/resolvers/base.rb)
121
+ respectively, to take advantage of some of the methods provided by devise
122
+ just like with `devise_scope`
93
123
 
94
124
  #### Available Operations
95
125
  The following is a list of the symbols you can provide to the `operations`, `skip` and `only` options of the mount method:
@@ -7,7 +7,7 @@ module GraphqlDevise
7
7
  argument :confirm_success_url, String, required: false
8
8
 
9
9
  def resolve(confirm_success_url: nil, **attrs)
10
- resource = resource_class.new(provider: provider, **attrs)
10
+ resource = build_resource(attrs.merge(provider: provider))
11
11
  raise_user_error(I18n.t('graphql_devise.resource_build_failed')) if resource.blank?
12
12
 
13
13
  redirect_url = confirm_success_url || DeviseTokenAuth.default_confirm_success_url
@@ -45,6 +45,10 @@ module GraphqlDevise
45
45
 
46
46
  private
47
47
 
48
+ def build_resource(attrs)
49
+ resource_class.new(attrs)
50
+ end
51
+
48
52
  def provider
49
53
  :email
50
54
  end
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.4"
6
+ gem "devise_token_auth", github: "lynndylanhurley/devise_token_auth", branch: "master"
7
+ gem "devise", ">= 4.7"
8
+ gem "rails", github: "rails/rails", branch: "6-0-stable"
9
+ gem "graphql", github: "rmosolgo/graphql-ruby", branch: "master"
10
+
11
+ gemspec path: "../"
@@ -1,9 +1,11 @@
1
1
  module ActionDispatch::Routing
2
2
  class Mapper
3
3
  def mount_graphql_devise_for(resource, opts = {})
4
- custom_operations = opts[:operations] || {}
5
- skipped_operations = opts.fetch(:skip, [])
6
- only_operations = opts.fetch(:only, [])
4
+ custom_operations = opts.fetch(:operations, {})
5
+ skipped_operations = opts.fetch(:skip, [])
6
+ only_operations = opts.fetch(:only, [])
7
+ additional_mutations = opts.fetch(:additional_mutations, {})
8
+ additional_queries = opts.fetch(:additional_queries, {})
7
9
 
8
10
  if [skipped_operations, only_operations].all?(&:any?)
9
11
  raise GraphqlDevise::Error, "Can't specify both `skip` and `only` options when mounting the route."
@@ -62,8 +64,11 @@ module ActionDispatch::Routing
62
64
 
63
65
  GraphqlDevise::Types::MutationType.field("#{mapping_name}_#{action}", mutation: used_mutation)
64
66
  end
67
+ additional_mutations.each do |action, mutation|
68
+ GraphqlDevise::Types::MutationType.field(action, mutation: mutation)
69
+ end
65
70
 
66
- if used_mutations.present? &&
71
+ if (used_mutations.present? || additional_mutations.present?) &&
67
72
  (Gem::Version.new(GraphQL::VERSION) <= Gem::Version.new('1.10.0') || GraphqlDevise::Schema.mutation.nil?)
68
73
  GraphqlDevise::Schema.mutation(GraphqlDevise::Types::MutationType)
69
74
  end
@@ -87,8 +92,11 @@ module ActionDispatch::Routing
87
92
 
88
93
  GraphqlDevise::Types::QueryType.field("#{mapping_name}_#{action}", resolver: used_query)
89
94
  end
95
+ additional_queries.each do |action, resolver|
96
+ GraphqlDevise::Types::QueryType.field(action, resolver: resolver)
97
+ end
90
98
 
91
- if used_queries.blank? && GraphqlDevise::Types::QueryType.fields.blank?
99
+ if (used_queries.blank? || additional_queries.present?) && GraphqlDevise::Types::QueryType.fields.blank?
92
100
  GraphqlDevise::Types::QueryType.field(:dummy, resolver: GraphqlDevise::Resolvers::Dummy)
93
101
  end
94
102
 
@@ -1,3 +1,3 @@
1
1
  module GraphqlDevise
2
- VERSION = '0.9.2'.freeze
2
+ VERSION = '0.10.0'.freeze
3
3
  end
@@ -0,0 +1,23 @@
1
+ module Mutations
2
+ class RegisterConfirmedUser < GraphqlDevise::Mutations::Base
3
+ argument :email, String, required: true
4
+ argument :name, String, required: true
5
+ argument :password, String, required: true
6
+ argument :password_confirmation, String, required: true
7
+
8
+ field :user, Types::UserType, null: true
9
+
10
+ def resolve(**attrs)
11
+ user = User.new(attrs.merge(confirmed_at: Time.zone.now))
12
+
13
+ if user.save
14
+ { user: user }
15
+ else
16
+ raise_user_error_list(
17
+ 'Custom registration failed',
18
+ errors: user.errors.full_messages
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module Resolvers
2
+ class PublicUser < GraphQL::Schema::Resolver
3
+ type Types::UserType, null: false
4
+
5
+ argument :id, Int, required: true
6
+
7
+ def resolve(id:)
8
+ User.find(id)
9
+ end
10
+ end
11
+ end
@@ -2,6 +2,10 @@ Rails.application.routes.draw do
2
2
  mount_graphql_devise_for 'User', at: '/api/v1/graphql_auth', operations: {
3
3
  login: Mutations::Login,
4
4
  sign_up: Mutations::SignUp
5
+ }, additional_mutations: {
6
+ register_confirmed_user: Mutations::RegisterConfirmedUser
7
+ }, additional_queries: {
8
+ public_user: Resolvers::PublicUser
5
9
  }
6
10
 
7
11
  mount_graphql_devise_for(