Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def set_resource_by_token(resource)
end

def graphql_context(resource_name)
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
`graphql_context` is deprecated and will be removed in a future version of this gem.
Use `gql_devise_context(models)` instead.

EXAMPLE
include GraphqlDevise::Concerns::SetUserByToken

DummySchema.execute(params[:query], context: gql_devise_context(User))
DummySchema.execute(params[:query], context: gql_devise_context([User, Admin]))
DEPRECATION

{
resource_name: resource_name,
controller: self
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/graphql_devise/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def mount_in_schema
query: Types::QueryType,
mutation: Types::MutationType,
resource_loaders: [
GraphqlDevise::ResourceLoader.new('#{user_class}'),
GraphqlDevise::ResourceLoader.new(#{user_class})
]
)
RUBY
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql_devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.add_mapping(mapping_name, resource)

Devise.add_mapping(
mapping_name.to_s.pluralize.to_sym,
module: :devise, class_name: resource
module: :devise, class_name: resource.to_s
)
end

Expand Down
16 changes: 15 additions & 1 deletion lib/graphql_devise/resource_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@ def call(query, mutation)
# clean_options responds to all keys defined in GraphqlDevise::MountMethod::SUPPORTED_OPTIONS
clean_options = GraphqlDevise::MountMethod::OptionSanitizer.new(@options).call!

model = @resource.is_a?(String) ? @resource.constantize : @resource
model = if @resource.is_a?(String)
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
Providing a String as the model you want to mount is deprecated and will be removed in a future version of
this gem. Please use the actual model constant instead.

EXAMPLE

GraphqlDevise::ResourceLoader.new(User) # instead of GraphqlDevise::ResourceLoader.new('User')

mount_graphql_devise_for User # instead of mount_graphql_devise_for 'User'
DEPRECATION
@resource.constantize
else
@resource
end

# Necesary when mounting a resource via route file as Devise forces the reloading of routes
return clean_options if GraphqlDevise.resource_mounted?(model) && @routing
Expand Down
14 changes: 14 additions & 0 deletions lib/graphql_devise/schema_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ def trace(event, trace_data)
auth_required = authenticate_option(field, trace_data)
context = context_from_data(trace_data)

if context.key?(:resource_name)
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
Providing `resource_name` as part of the GQL context, or doing so by using the `graphql_context(resource_name)`
method on your controller is deprecated and will be removed in a future version of this gem.
Please use `gql_devise_context` in you controller instead.

EXAMPLE
include GraphqlDevise::Concerns::SetUserByToken

DummySchema.execute(params[:query], context: gql_devise_context(User))
DummySchema.execute(params[:query], context: gql_devise_context([User, Admin]))
DEPRECATION
end

if auth_required && !(public_introspection && introspection_field?(field))
context = set_current_resource(context)
raise_on_missing_resource(context, field)
Expand Down
2 changes: 1 addition & 1 deletion spec/generators/graphql_devise/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

assert_file 'app/controllers/application_controller.rb', /^\s{2}include GraphqlDevise::Concerns::SetUserByToken/

assert_file 'app/graphql/gqld_dummy_schema.rb', /\s+#{Regexp.escape("GraphqlDevise::ResourceLoader.new('Admin')")}/
assert_file 'app/graphql/gqld_dummy_schema.rb', /\s+#{Regexp.escape("GraphqlDevise::ResourceLoader.new(Admin)")}/
end
end

Expand Down