Sha256: 75193d58710bacde447a6f1056bcb48b41974f94372b5f659b76601c9d215c0a

Contents?: true

Size: 998 Bytes

Versions: 57

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

57 entries across 57 versions & 1 rubygems

Version Path
shopify-cli-2.10.1 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.10.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.9.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.8.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.7.4 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.7.3 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.7.2 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.7.1 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.7.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.6.6 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.6.5 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.6.4 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.6.3 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.6.2 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.6.1 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.6.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.5.0 lib/shopify_cli/admin_api/schema.rb