Home > database >  undefined method for Queries:Module
undefined method for Queries:Module

Time:09-22

I am building some tests for a query from graphql, at a rails app, but i keep getting this error: "undefined method `AllUsers' for Queries:Module". Im not sure, but i think it is related to the module. Can anyone help, me please?

  • All Users Query

module Queries
  class AllUsers < BaseQuery
    type [Types::UserType], null: false
    description 'Fetch all users'

    def resolve
      User.all
    end
  end
end

  • All Users Rspec

require 'rails_helper'


  RSpec.describe Queries::AllUsers type: :request do
    describe 'Query' do
      it 'Successfully returns all users' do
        post '/graphql', params: { query: }
        json = JSON.parse(response.body)
        data = json['data']['users']
        expect(data).to match_array [hash_including('id' => be_present, 'firstName' => be_present,
                                                    'lastName' => be_present, 'email' => be_present)]
      end
    end

    def query_user
      <<~GQL
        query{
            users{
            id
            firstName
            lastName
            email
            }
        }
      GQL
    end
  end

CodePudding user response:

Did you miss the comma?

Behind Queries::AllUsers need ,

...

RSpec.describe Queries::AllUsers, type: :request do

...
  • Related