Don't access the database in after_initialize
Rails 5.2 crashes in the `db:create` task because it tries to run the `after_initialize` block before the database is created. The easiest way to solve it is to move the code out of the initializer and calculate the API type definitions on demand. Note results are still cached using a class instance variable (not to be confused with a class variable), and so once definitions are obtained, they will remain constant until the application is restarted, even in the development environment.
This commit is contained in:
@@ -10,7 +10,7 @@ module GraphQL
|
||||
string: GraphQL::STRING_TYPE
|
||||
}.freeze
|
||||
|
||||
def self.create(api_types_definitions)
|
||||
def self.create
|
||||
created_types = {}
|
||||
api_types_definitions.each do |model, info|
|
||||
create_type(model, info[:fields], created_types)
|
||||
@@ -18,6 +18,10 @@ module GraphQL
|
||||
created_types
|
||||
end
|
||||
|
||||
def self.api_types_definitions
|
||||
@api_types_definitions ||= parse_api_config_file(YAML.load_file(Rails.root.join("config/api.yml")))
|
||||
end
|
||||
|
||||
def self.type_kind(type)
|
||||
if SCALAR_TYPES[type]
|
||||
:scalar
|
||||
|
||||
Reference in New Issue
Block a user