Skip to content

Commit

Permalink
Create shopify theme metafields pull command
Browse files Browse the repository at this point in the history
  • Loading branch information
aswamy committed Nov 13, 2024
1 parent 300c6aa commit 122461c
Show file tree
Hide file tree
Showing 22 changed files with 875 additions and 17 deletions.
8 changes: 8 additions & 0 deletions .changeset/nervous-terms-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@shopify/theme': minor
'@shopify/cli': minor
---

New CLI command under `shopify theme` to pull metafield definitions from the shop

Run command by calling `shopify theme metafields pull`
5 changes: 5 additions & 0 deletions .changeset/quick-eggs-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-kit': patch
---

Introduce method to fetch metafield definitions by ownerType from Admin API
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shopify theme metafields pull [flags]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This is an autogenerated file. Don't edit this file manually.
export interface thememetafieldspull {
/**
* The environment to apply to the current command.
* @environment SHOPIFY_FLAG_ENVIRONMENT
*/
'-e, --environment <value>'?: string

/**
* Disable color output.
* @environment SHOPIFY_FLAG_NO_COLOR
*/
'--no-color'?: ''

/**
* Password generated from the Theme Access app.
* @environment SHOPIFY_CLI_THEME_TOKEN
*/
'--password <value>'?: string

/**
* The path to your theme directory.
* @environment SHOPIFY_FLAG_PATH
*/
'--path <value>'?: string

/**
* Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).
* @environment SHOPIFY_FLAG_STORE
*/
'-s, --store <value>'?: string

/**
* Increase the verbosity of the output.
* @environment SHOPIFY_FLAG_VERBOSE
*/
'--verbose'?: ''
}
36 changes: 36 additions & 0 deletions docs-shopify.dev/commands/theme-metafields-pull.doc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This is an autogenerated file. Don't edit this file manually.
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'

const data: ReferenceEntityTemplateSchema = {
name: 'theme metafields pull',
description: `Retrieves metafields from Shopify Admin.
If the metafields file already exists, it will be overwritten.`,
overviewPreviewDescription: `Download metafields definitions from your shop into a local file.`,
type: 'command',
isVisualComponent: false,
defaultExample: {
codeblock: {
tabs: [
{
title: 'theme metafields pull',
code: './examples/theme-metafields-pull.example.sh',
language: 'bash',
},
],
title: 'theme metafields pull',
},
},
definitions: [
{
title: 'Flags',
description: 'The following flags are available for the `theme metafields pull` command:',
type: 'thememetafieldspull',
},
],
category: 'theme',
related: [
],
}

export default data
92 changes: 92 additions & 0 deletions docs-shopify.dev/generated/generated_docs_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5332,6 +5332,98 @@
"category": "theme",
"related": []
},
{
"name": "theme metafields pull",
"description": "Retrieves metafields from Shopify Admin.\n\nIf the metafields file already exists, it will be overwritten.",
"overviewPreviewDescription": "Download metafields definitions from your shop into a local file.",
"type": "command",
"isVisualComponent": false,
"defaultExample": {
"codeblock": {
"tabs": [
{
"title": "theme metafields pull",
"code": "shopify theme metafields pull [flags]",
"language": "bash"
}
],
"title": "theme metafields pull"
}
},
"definitions": [
{
"title": "Flags",
"description": "The following flags are available for the `theme metafields pull` command:",
"type": "thememetafieldspull",
"typeDefinitions": {
"thememetafieldspull": {
"filePath": "docs-shopify.dev/commands/interfaces/theme-metafields-pull.interface.ts",
"name": "thememetafieldspull",
"description": "",
"members": [
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-metafields-pull.interface.ts",
"syntaxKind": "PropertySignature",
"name": "--no-color",
"value": "\"\"",
"description": "Disable color output.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_NO_COLOR"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-metafields-pull.interface.ts",
"syntaxKind": "PropertySignature",
"name": "--password <value>",
"value": "string",
"description": "Password generated from the Theme Access app.",
"isOptional": true,
"environmentValue": "SHOPIFY_CLI_THEME_TOKEN"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-metafields-pull.interface.ts",
"syntaxKind": "PropertySignature",
"name": "--path <value>",
"value": "string",
"description": "The path to your theme directory.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_PATH"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-metafields-pull.interface.ts",
"syntaxKind": "PropertySignature",
"name": "--verbose",
"value": "\"\"",
"description": "Increase the verbosity of the output.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_VERBOSE"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-metafields-pull.interface.ts",
"syntaxKind": "PropertySignature",
"name": "-e, --environment <value>",
"value": "string",
"description": "The environment to apply to the current command.",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_ENVIRONMENT"
},
{
"filePath": "docs-shopify.dev/commands/interfaces/theme-metafields-pull.interface.ts",
"syntaxKind": "PropertySignature",
"name": "-s, --store <value>",
"value": "string",
"description": "Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).",
"isOptional": true,
"environmentValue": "SHOPIFY_FLAG_STORE"
}
],
"value": "export interface thememetafieldspull {\n /**\n * The environment to apply to the current command.\n * @environment SHOPIFY_FLAG_ENVIRONMENT\n */\n '-e, --environment <value>'?: string\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Password generated from the Theme Access app.\n * @environment SHOPIFY_CLI_THEME_TOKEN\n */\n '--password <value>'?: string\n\n /**\n * The path to your theme directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).\n * @environment SHOPIFY_FLAG_STORE\n */\n '-s, --store <value>'?: string\n\n /**\n * Increase the verbosity of the output.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
}
}
}
],
"category": "theme",
"related": []
},
{
"name": "theme open",
"description": "Returns links that let you preview the specified theme. The following links are returned:\n\n - A link to the [editor](/docs/themes/tools/online-editor) for the theme in the Shopify admin.\n - A [preview link](https://help.shopify.com/manual/online-store/themes/adding-themes#share-a-theme-preview-with-others) that you can share with other developers.\n\n If you don't specify a theme, then you're prompted to select the theme to open from the list of the themes in your store.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export type Scalars = {
ISO8601Date: {input: any; output: any}
/** An ISO 8601-encoded datetime */
ISO8601DateTime: {input: any; output: any}
/** The ID for a LegalEntity. */
LegalEntityID: {input: any; output: any}
/** The ID for a OrganizationDomain. */
OrganizationDomainID: {input: any; output: any}
/** The ID for a Organization. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import * as Types from './types.js'

import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'

export type MetafieldDefinitionsByOwnerTypeQueryVariables = Types.Exact<{
ownerType: Types.MetafieldOwnerType
}>

export type MetafieldDefinitionsByOwnerTypeQuery = {
metafieldDefinitions: {
nodes: {
key: string
name: string
namespace: string
description?: string | null
type: {category: string; name: string}
}[]
}
}

export const MetafieldDefinitionsByOwnerType = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: {kind: 'Name', value: 'metafieldDefinitionsByOwnerType'},
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {kind: 'Variable', name: {kind: 'Name', value: 'ownerType'}},
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'MetafieldOwnerType'}}},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'metafieldDefinitions'},
arguments: [
{
kind: 'Argument',
name: {kind: 'Name', value: 'ownerType'},
value: {kind: 'Variable', name: {kind: 'Name', value: 'ownerType'}},
},
{kind: 'Argument', name: {kind: 'Name', value: 'first'}, value: {kind: 'IntValue', value: '250'}},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: {kind: 'Name', value: 'nodes'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'key'}},
{kind: 'Field', name: {kind: 'Name', value: 'name'}},
{kind: 'Field', name: {kind: 'Name', value: 'namespace'}},
{kind: 'Field', name: {kind: 'Name', value: 'description'}},
{
kind: 'Field',
name: {kind: 'Name', value: 'type'},
selectionSet: {
kind: 'SelectionSet',
selections: [
{kind: 'Field', name: {kind: 'Name', value: 'category'}},
{kind: 'Field', name: {kind: 'Name', value: 'name'}},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
{kind: 'Field', name: {kind: 'Name', value: '__typename'}},
],
},
},
],
},
},
],
} as unknown as DocumentNode<MetafieldDefinitionsByOwnerTypeQuery, MetafieldDefinitionsByOwnerTypeQueryVariables>
61 changes: 61 additions & 0 deletions packages/cli-kit/src/cli/api/graphql/admin/generated/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,67 @@ export type Scalars = {
UtcOffset: {input: any; output: any}
}

/** Possible types of a metafield's owner resource. */
export type MetafieldOwnerType =
/** The Api Permission metafield owner type. */
| 'API_PERMISSION'
/** The Article metafield owner type. */
| 'ARTICLE'
/** The Blog metafield owner type. */
| 'BLOG'
/** The Brand metafield owner type. */
| 'BRAND'
/** The Cart Transform metafield owner type. */
| 'CARTTRANSFORM'
/** The Collection metafield owner type. */
| 'COLLECTION'
/** The Company metafield owner type. */
| 'COMPANY'
/** The Company Location metafield owner type. */
| 'COMPANY_LOCATION'
/** The Customer metafield owner type. */
| 'CUSTOMER'
/** The Delivery Customization metafield owner type. */
| 'DELIVERY_CUSTOMIZATION'
/** The Delivery Method metafield owner type. */
| 'DELIVERY_METHOD'
/** The Delivery Option Generator metafield owner type. */
| 'DELIVERY_OPTION_GENERATOR'
/** The Discount metafield owner type. */
| 'DISCOUNT'
/** The draft order metafield owner type. */
| 'DRAFTORDER'
/** The Fulfillment Constraint Rule metafield owner type. */
| 'FULFILLMENT_CONSTRAINT_RULE'
/** The Gate Configuration metafield owner type. */
| 'GATE_CONFIGURATION'
/** The GiftCardTransaction metafield owner type. */
| 'GIFT_CARD_TRANSACTION'
/** The Location metafield owner type. */
| 'LOCATION'
/** The Market metafield owner type. */
| 'MARKET'
/** The Media Image metafield owner type. */
| 'MEDIA_IMAGE'
/** The Order metafield owner type. */
| 'ORDER'
/** The Order Routing Location Rule metafield owner type. */
| 'ORDER_ROUTING_LOCATION_RULE'
/** The Page metafield owner type. */
| 'PAGE'
/** The Payment Customization metafield owner type. */
| 'PAYMENT_CUSTOMIZATION'
/** The Product metafield owner type. */
| 'PRODUCT'
/** The Product Variant metafield owner type. */
| 'PRODUCTVARIANT'
/** The Selling Plan metafield owner type. */
| 'SELLING_PLAN'
/** The Shop metafield owner type. */
| 'SHOP'
/** The Validation metafield owner type. */
| 'VALIDATION'

/** Type of a theme file operation result. */
export type OnlineStoreThemeFileResultType =
/** Operation was malformed or invalid. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query metafieldDefinitionsByOwnerType($ownerType: MetafieldOwnerType!) {
metafieldDefinitions(ownerType: $ownerType, first: 250) {
nodes {
key
name
namespace
description
type {
category
name
}
}
}
}
Loading

0 comments on commit 122461c

Please sign in to comment.