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.36.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.35.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.34.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.33.1 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.33.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.32.1 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.32.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.31.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.30.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.29.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.28.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.27.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.26.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.25.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.24.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.23.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.22.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.21.0 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.20.1 lib/shopify_cli/admin_api/schema.rb
shopify-cli-2.20.0 lib/shopify_cli/admin_api/schema.rb