Class: ShopifyCLI::AdminAPI::Schema

Inherits:
Hash
  • Object
show all
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 = 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

Instance Method Details

#get_names_from_type(name) ⇒ Object



28
29
30
31
32
# File 'lib/shopify_cli/admin_api/schema.rb', line 28

def get_names_from_type(name)
  type(name)["enumValues"].map do |object|
    object["name"]
  end
end

#type(name) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/shopify_cli/admin_api/schema.rb', line 20

def type(name)
  data = self["data"]
  schema = data["__schema"]
  schema["types"].find do |object|
    object["name"] == name.to_s
  end
end