Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #793 from Shopify/fix_schema_get_shop
Browse files Browse the repository at this point in the history
Make schema.get_shop a class method
  • Loading branch information
paulomarg authored Aug 4, 2020
2 parents cb6f448 + 8caa1a4 commit 3688848
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/shopify-cli/admin_api/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
module ShopifyCli
class AdminAPI
class Schema < Hash
def self.get(ctx)
unless ShopifyCli::DB.exists?(:shopify_admin_schema)
shop = Project.current.env.shop || get_shop(@ctx)
schema = AdminAPI.query(ctx, 'admin_introspection', shop: shop)
ShopifyCli::DB.set(shopify_admin_schema: JSON.dump(schema))
class << self
def get(ctx)
unless ShopifyCli::DB.exists?(:shopify_admin_schema)
shop = Project.current.env.shop || get_shop(ctx)
schema = AdminAPI.query(ctx, 'admin_introspection', shop: shop)
ShopifyCli::DB.set(shopify_admin_schema: JSON.dump(schema))
end
# This is ruby magic for making a new hash with another hash.
# It wraps the JSON in our Schema Class to have the helper methods
# available
self[JSON.parse(ShopifyCli::DB.get(:shopify_admin_schema))]
end

private

def get_shop(ctx)
res = ShopifyCli::Tasks::SelectOrgAndShop.call(ctx)
domain = res[:shop_domain]
Project.current.env.update(ctx, :shop, domain)
domain
end
# This is ruby magic for making a new hash with another hash.
# It wraps the JSON in our Schema Class to have the helper methods
# available
self[JSON.parse(ShopifyCli::DB.get(:shopify_admin_schema))]
end

def type(name)
Expand All @@ -28,15 +39,6 @@ def get_names_from_type(name)
object["name"]
end
end

private

def get_shop(ctx)
res = ShopifyCli::Tasks::SelectOrgAndShop.call(ctx)
domain = res[:shop_domain]
Project.current.env.update(ctx, :shop, domain)
domain
end
end
end
end

0 comments on commit 3688848

Please sign in to comment.