{"action":"created","issue":{"url":"https://api.github.com/repos/rmosolgo/graphql-ruby/issues/1312","repository_url":"https://api.github.com/repos/rmosolgo/graphql-ruby","labels_url":"https://api.github.com/repos/rmosolgo/graphql-ruby/issues/1312/labels{/name}","comments_url":"https://api.github.com/repos/rmosolgo/graphql-ruby/issues/1312/comments","events_url":"https://api.github.com/repos/rmosolgo/graphql-ruby/issues/1312/events","html_url":"https://github.com/rmosolgo/graphql-ruby/issues/1312","id":300515469,"number":1312,"title":"exception LoadError: Unable to autoload constant","user":{"login":"cyb-ahmadh","id":17269118,"avatar_url":"https://avatars0.githubusercontent.com/u/17269118?v=4","gravatar_id":"","url":"https://api.github.com/users/cyb-ahmadh","html_url":"https://github.com/cyb-ahmadh","followers_url":"https://api.github.com/users/cyb-ahmadh/followers","following_url":"https://api.github.com/users/cyb-ahmadh/following{/other_user}","gists_url":"https://api.github.com/users/cyb-ahmadh/gists{/gist_id}","starred_url":"https://api.github.com/users/cyb-ahmadh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyb-ahmadh/subscriptions","organizations_url":"https://api.github.com/users/cyb-ahmadh/orgs","repos_url":"https://api.github.com/users/cyb-ahmadh/repos","events_url":"https://api.github.com/users/cyb-ahmadh/events{/privacy}","received_events_url":"https://api.github.com/users/cyb-ahmadh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-27T07:04:56Z","updated_at":"2018-02-27T16:36:05Z","closed_at":null,"author_association":"NONE","body":"Hi, \r\n\r\nI'm using graphql(1.7.9), rails-api (5.1.4) and ruby(2.5.0p0).\r\nFor the `queries` in `query_type.rb` file, i have used `functions` to cleaner approach. So i have created one folder inside the graphql folder for functions and put all the functions there. As expected i am using those functions in query_type.rb file like this:\r\n\r\n```\r\nfield :user, function: Functions::FindRecord.new(model_class: User, type: Types::UserType)\r\nfield :activeUsers, function: Functions::ActiveUsers.new(type: types[Types::UserType])\r\nfield :nonActiveUsers, function: Functions::NonActiveUsers.new(type: types[Types::UserType])\r\n```\r\n- Function definitions\r\n```\r\n#app/graphql/functions/find_record.rb\r\nmodule Functions\r\n  class FindRecord < GraphQL::Function\r\n    attr_reader :type\r\n\r\n    def initialize(model_class:, type:)\r\n      @model_class = model_class\r\n      @type = type\r\n    end\r\n\r\n    argument :id, !types.Int\r\n\r\n    def call(obj, args, ctx)\r\n      @model_class.find(args[:id])\r\n    end\r\n  end\r\nend\r\n\r\n#app/graphql/functions/all_users.rb\r\nmodule Functions\r\n  class AllUsers < GraphQL::Function\r\n    attr_reader :type\r\n\r\n    def initialize(type:)\r\n      @type = type\r\n    end\r\n\r\n    def call(_, args, _)\r\n      User.all\r\n    end\r\n  end\r\n\r\n  class ActiveUsers < AllUsers\r\n    def call(_, args, _)\r\n      super.active\r\n    end\r\n  end\r\n\r\n  class CompletedUsers < AllUsers\r\n    def call(_, args, _)\r\n      super.non_active\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nNow when i'm hitting `graphiql`, it says this:\r\n```\r\n{\r\n  \"status\": 500,\r\n  \"error\": \"Internal Server Error\",\r\n  \"exception\": \"#<LoadError: Unable to autoload constant Functions::FindRecord, expected /usr/src/app/app/graphql/functions/find_record.rb to define it>\",\r\n  \"traces\": {\r\n    \"Application Trace\": [\r\n      {\r\n        \"id\": 2,\r\n        \"trace\": \"app/graphql/types/query_type.rb:5:in `block in <top (required)>'\"\r\n      },\r\n      {\r\n        \"id\": 19,\r\n        \"trace\": \"app/graphql/user_service_schema.rb:3:in `<top (required)>'\"\r\n      },\r\n      {\r\n        \"id\": 35,\r\n        \"trace\": \"app/controllers/graphql_controller.rb:10:in `execute'\"\r\n      }\r\n    ],\r\n    \"Framework Trace\": [\r\n      {\r\n        \"id\": 0,\r\n        \"trace\": \"activesupport (5.1.4) lib/active_support/dependencies.rb:511:in `load_missing_constant'\"\r\n      },\r\n      {\r\n        \"id\": 1,\r\n        \"trace\": \"activesupport (5.1.4) lib/active_support/dependencies.rb:202:in `const_missing'\"\r\n      },\r\n      {\r\n        \"id\": 3,\r\n        \"trace\": \"graphql (1.7.9) lib/graphql/define/instance_definable.rb:161:in `instance_eval'\"\r\n      },\r\n...\r\n```\r\n\r\nI have to then manually require the files in schema file like this:\r\n\r\n```\r\nrequire 'types/mutation_type'\r\nrequire 'functions/all_users'\r\n```\r\nThe same thing happened for mutation_type file as well. Please suggest what am i missing or doing wrong here. "},"comment":{"url":"https://api.github.com/repos/rmosolgo/graphql-ruby/issues/comments/368940620","html_url":"https://github.com/rmosolgo/graphql-ruby/issues/1312#issuecomment-368940620","issue_url":"https://api.github.com/repos/rmosolgo/graphql-ruby/issues/1312","id":368940620,"user":{"login":"cyb-ahmadh","id":17269118,"avatar_url":"https://avatars0.githubusercontent.com/u/17269118?v=4","gravatar_id":"","url":"https://api.github.com/users/cyb-ahmadh","html_url":"https://github.com/cyb-ahmadh","followers_url":"https://api.github.com/users/cyb-ahmadh/followers","following_url":"https://api.github.com/users/cyb-ahmadh/following{/other_user}","gists_url":"https://api.github.com/users/cyb-ahmadh/gists{/gist_id}","starred_url":"https://api.github.com/users/cyb-ahmadh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyb-ahmadh/subscriptions","organizations_url":"https://api.github.com/users/cyb-ahmadh/orgs","repos_url":"https://api.github.com/users/cyb-ahmadh/repos","events_url":"https://api.github.com/users/cyb-ahmadh/events{/privacy}","received_events_url":"https://api.github.com/users/cyb-ahmadh/received_events","type":"User","site_admin":false},"created_at":"2018-02-27T16:36:05Z","updated_at":"2018-02-27T16:36:05Z","author_association":"NONE","body":"I think there is no need of it because of this result:\r\n```\r\nbin/rails r 'puts ActiveSupport::Dependencies.autoload_paths'\r\nRunning via Spring preloader in process 26\r\n/usr/src/app/app/controllers\r\n/usr/src/app/app/graphql\r\n/usr/src/app/app/models\r\n/usr/local/bundle/gems/graphiql-rails-1.4.8/app/assets\r\n/usr/local/bundle/gems/graphiql-rails-1.4.8/app/controllers\r\n\r\n```"}}
{"actor":{"display_login":"cyb-ahmadh"}}