Skip to content

Commit 3f1f7dd

Browse files
authored
Merge pull request #693 from Shopify/do-not-raise-on-schema-name-invalid
Add option to not raise if non-matching schema name
2 parents c9178cc + 01703c9 commit 3f1f7dd

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/shopify_api/graphql.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def clear_clients
3939
@_client_cache = {}
4040
end
4141

42-
def initialize_clients
42+
def initialize_clients(raise_on_invalid_schema: true)
4343
initialize_client_cache
4444

4545
Dir.glob(schema_location.join("*.json")).each do |schema_file|
@@ -49,7 +49,11 @@ def initialize_clients
4949
if matches
5050
api_version = ShopifyAPI::ApiVersion.new(handle: matches[1])
5151
else
52-
raise InvalidSchema, "Invalid schema file name `#{schema_file}`. Does not match format of: `<version>.json`."
52+
if raise_on_invalid_schema
53+
raise InvalidSchema, "Invalid schema file name `#{schema_file}`. Does not match format of: `<version>.json`."
54+
else
55+
next
56+
end
5357
end
5458

5559
schema = ::GraphQL::Client.load_schema(schema_file.to_s)

test/graphql_test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ def teardown
5353
end
5454
end
5555

56+
test '#initialize_clients does not raise if raise_on_invalid_schema is set to false' do
57+
version_fixtures('unstable') do |dir|
58+
ShopifyAPI::GraphQL.schema_location = dir
59+
FileUtils.touch(ShopifyAPI::GraphQL.schema_location.join('nope.json'))
60+
61+
ShopifyAPI::GraphQL.initialize_clients(raise_on_invalid_schema: false)
62+
63+
assert ShopifyAPI::GraphQL.client('unstable')
64+
end
65+
end
66+
5667
test '#client returns default schema if only one exists' do
5768
version_fixtures('unstable') do |dir|
5869
ShopifyAPI::Base.api_version = 'unstable'

0 commit comments

Comments
 (0)