diff --git a/lib/shopify_api/graphql.rb b/lib/shopify_api/graphql.rb index 67166a0ec..2c55161c4 100644 --- a/lib/shopify_api/graphql.rb +++ b/lib/shopify_api/graphql.rb @@ -39,7 +39,7 @@ def clear_clients @_client_cache = {} end - def initialize_clients + def initialize_clients(raise_on_invalid_schema: true) initialize_client_cache Dir.glob(schema_location.join("*.json")).each do |schema_file| @@ -49,7 +49,9 @@ def initialize_clients if matches api_version = ShopifyAPI::ApiVersion.new(handle: matches[1]) else - raise InvalidSchema, "Invalid schema file name `#{schema_file}`. Does not match format of: `.json`." + if raise_on_invalid_schema + raise InvalidSchema, "Invalid schema file name `#{schema_file}`. Does not match format of: `.json`." + end end schema = ::GraphQL::Client.load_schema(schema_file.to_s) diff --git a/test/graphql_test.rb b/test/graphql_test.rb index 39d05f66a..36e6ff91b 100644 --- a/test/graphql_test.rb +++ b/test/graphql_test.rb @@ -53,6 +53,17 @@ def teardown end end + test '#initialize_clients does not raise if raise_on_invalid_schema is set to false' do + version_fixtures('unstable') do |dir| + ShopifyAPI::GraphQL.schema_location = dir + FileUtils.touch(ShopifyAPI::GraphQL.schema_location.join('nope.json')) + + ShopifyAPI::GraphQL.initialize_clients(raise_on_invalid_schema: false) + + assert ShopifyAPI::GraphQL.client('unstable') + end + end + test '#client returns default schema if only one exists' do version_fixtures('unstable') do |dir| ShopifyAPI::Base.api_version = 'unstable'