Skip to content

Devise mapping error #103

@pelarejo

Description

@pelarejo

Describe the bug

Hi,
I've been trying to install graphql_devise in a rails API app.
After initializing the gem to be mounted in the schema,
the before_action in graphql_controller set_resource_by_token(:user) fails with:

NoMethodError (undefined method `to' for nil:NilClass)

I suspect a failure in mounting devise or I misunderstood something.

Environment

Gemfile:
https://github.com/pelarejo/gql_devise_error_demo/blob/master/Gemfile

Gemfile.lock:
https://github.com/pelarejo/gql_devise_error_demo/blob/master/Gemfile.lock

Steps to reproduce

I have installed the gem as describe in the demo project's README.
Start the rails server and fetch the schema or launch the userLogin mutation.

More details below.

Expected behavior

I exepected to be able to login straight away.

Digging a little, this error comes from Devise.mappings being empty during devise_token_auth#resource_class after the controller execute set_resource_by_token(:user)

I expected the GraphqlDevise::ResourceLoader in the schema added through the generator to programatically mount the devise module. Isn't that why it's for ?

Actual behavior

The graphql_controller set_resource_by_token call fails with:
NoMethodError (undefined method `to' for nil:NilClass)

Here is the graphql stacktrace:
https://gist.github.com/pelarejo/4a3f9d58898ead574bf1552ae4ba331a

Reproducible demo

Clone this repo:
https://github.com/pelarejo/gql_devise_error_demo

Start the server:

$ bundle
$ rails db:migrate
$ rails server

Launch the query:

curl --request POST \
  --url http://localhost:3000/graphql \
  --header 'content-type: application/json' \
  --data '{"query":"mutation userLogin($email: String!, $password: String!) {\n  userLogin(email: $email, password: $password) {\n    credentials {\n      client\n      accessToken\n      expiry\n      tokenType\n      uid\n    }\n  }\n}","variables":{"email":"user@example.com","password":"password123"},"operationName":"userLogin"}'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions