Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5080762

Browse files
committedMar 5, 2020
Add option to not raise if non-matching schema name
1 parent c9178cc commit 5080762

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
 

‎lib/shopify_api/graphql.rb

+4-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,9 @@ 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+
end
5355
end
5456

5557
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)
Please sign in to comment.