Skip to content

Commit

Permalink
Add option to not raise if non-matching schema name
Browse files Browse the repository at this point in the history
  • Loading branch information
Radu-Raicea committed Mar 5, 2020
1 parent c9178cc commit 5080762
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/shopify_api/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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: `<version>.json`."
if raise_on_invalid_schema
raise InvalidSchema, "Invalid schema file name `#{schema_file}`. Does not match format of: `<version>.json`."
end
end

schema = ::GraphQL::Client.load_schema(schema_file.to_s)
Expand Down
11 changes: 11 additions & 0 deletions test/graphql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 5080762

Please sign in to comment.