Sha256: 762a210b5a544f1cd0d9fe45848c61a86b080c7ed4aa8a51d22f9a6e18186fbc
Contents?: true
Size: 1.21 KB
Versions: 11
Compression:
Stored size: 1.21 KB
Contents
require "shopify_cli" module ShopifyCli class AdminAPI class Schema < Hash 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 end def type(name) data = self["data"] schema = data["__schema"] schema["types"].find do |object| object["name"] == name.to_s end end def get_names_from_type(name) type(name)["enumValues"].map do |object| object["name"] end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems