Sha256: b5f548eb8a26534dd54f50d536fb4f6f76c4caa2e12002563b83924ff7208a6b
Contents?: true
Size: 998 Bytes
Versions: 9
Compression:
Stored size: 998 Bytes
Contents
require "shopify_cli" module ShopifyCli class AdminAPI class Schema < Hash class << self def get(ctx) unless ShopifyCli::DB.exists?(:shopify_admin_schema) shop = AdminAPI.get_shop_or_abort(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 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
9 entries across 9 versions & 1 rubygems