Class: ShopifyCli::AdminAPI::Schema
- Inherits:
-
Hash
- Object
- Hash
- ShopifyCli::AdminAPI::Schema
- Defined in:
- lib/shopify-cli/admin_api/schema.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.get(ctx) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/shopify-cli/admin_api/schema.rb', line 7 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 |
Instance Method Details
#get_names_from_type(name) ⇒ Object
37 38 39 40 41 |
# File 'lib/shopify-cli/admin_api/schema.rb', line 37 def get_names_from_type(name) type(name)["enumValues"].map do |object| object["name"] end end |
#type(name) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/shopify-cli/admin_api/schema.rb', line 29 def type(name) data = self["data"] schema = data["__schema"] schema["types"].find do |object| object['name'] == name.to_s end end |