Skip to content

Commit bf832a0

Browse files
committed
fix metafield actions
1 parent 6d72280 commit bf832a0

File tree

7 files changed

+122
-28
lines changed

7 files changed

+122
-28
lines changed

components/shopify_developer_app/actions/common/metafield-actions.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default {
9898
},
9999
},
100100
customer: {
101-
...shopify.propDefinition.customerId,
101+
...shopify.propDefinitions.customerId,
102102
options: async ({ prevContext }) => {
103103
return this.shopify.getPropOptions({
104104
resourceFn: this.shopify.listCustomers,

components/shopify_developer_app/actions/create-metafield/create-metafield.mjs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import metafieldActions from "../common/metafield-actions.mjs";
22
import common from "@pipedream/shopify/actions/create-metafield/create-metafield.mjs";
33
import shopify from "../../shopify_developer_app.app.mjs";
4-
5-
import { adjustPropDefinitions } from "../../common/utils.mjs";
4+
import constants from "../common/constants.mjs";
65

76
const {
87
name, description, type, ...others
98
} = common;
10-
const props = adjustPropDefinitions(others.props, shopify);
119

1210
export default {
1311
...others,
@@ -18,8 +16,43 @@ export default {
1816
type,
1917
props: {
2018
shopify,
21-
...props,
22-
...common.props,
19+
ownerResource: {
20+
type: "string",
21+
label: "Resource Type",
22+
description: "Filter by the resource type on which the metafield is attached to",
23+
options: constants.RESOURCE_TYPES.map((type) => ({
24+
...type,
25+
value: type.value.toUpperCase(),
26+
})),
27+
},
28+
name: {
29+
type: "string",
30+
label: "Name",
31+
description: "The human-readable name for the metafield definition",
32+
},
33+
namespace: {
34+
type: "string",
35+
label: "Namespace",
36+
description: "A container for a group of metafields. Grouping metafields within a namespace prevents your metafields from conflicting with other metafields with the same key name. Must have between 3-255 characters.",
37+
},
38+
key: {
39+
type: "string",
40+
label: "Key",
41+
description: "The key of the metafield. Keys can be up to 64 characters long and can contain alphanumeric characters, hyphens, underscores, and periods.",
42+
},
43+
type: {
44+
type: "string",
45+
label: "Type",
46+
description: "The type of data that the metafield stores in the `value` field. Refer to the list of [supported types](https://shopify.dev/apps/custom-data/metafields/types).",
47+
options: Object.keys(constants.METAFIELD_TYPES),
48+
},
49+
pin: {
50+
type: "boolean",
51+
label: "Pin",
52+
description: "Whether to pin the metafield definition",
53+
default: false,
54+
optional: true,
55+
},
2356
},
2457
methods: {
2558
...metafieldActions.methods,

components/shopify_developer_app/actions/delete-metafield/delete-metafield.mjs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import metafieldActions from "../common/metafield-actions.mjs";
22
import common from "@pipedream/shopify/actions/delete-metafield/delete-metafield.mjs";
33
import shopify from "../../shopify_developer_app.app.mjs";
44

5-
import { adjustPropDefinitions } from "../../common/utils.mjs";
6-
75
const {
86
name, description, type, ...others
97
} = common;
10-
const props = adjustPropDefinitions(others.props, shopify);
118

129
export default {
1310
...others,
@@ -18,11 +15,38 @@ export default {
1815
type,
1916
props: {
2017
shopify,
21-
...props,
22-
...common.props,
18+
...metafieldActions.props,
2319
},
2420
methods: {
2521
...metafieldActions.methods,
26-
...common.methods,
22+
},
23+
async additionalProps() {
24+
const props = await this.getOwnerIdProp(this.ownerResource); console.log(props);
25+
26+
if (props.ownerId) {
27+
props.ownerId = {
28+
...props.ownerId,
29+
reloadProps: true,
30+
};
31+
}
32+
33+
if (this.ownerResource && this.ownerId) {
34+
props.metafieldId = {
35+
type: "string",
36+
label: "Metafield ID",
37+
description: "The metafield to update",
38+
options: async () => {
39+
const metafields = await this.listMetafields(this.ownerResource, this.ownerId);
40+
return metafields?.map(({
41+
id: value, key: label,
42+
}) => ({
43+
value,
44+
label,
45+
})) || [];
46+
},
47+
};
48+
}
49+
50+
return props;
2751
},
2852
};

components/shopify_developer_app/actions/get-metafields/get-metafields.mjs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,50 @@ import metafieldActions from "../common/metafield-actions.mjs";
22
import common from "@pipedream/shopify/actions/get-metafields/get-metafields.mjs";
33
import shopify from "../../shopify_developer_app.app.mjs";
44

5+
const {
6+
name, description, type,
7+
} = common;
8+
59
export default {
6-
...common,
710
key: "shopify_developer_app-get-metafields",
8-
name: "Get Metafields",
9-
description: "Retrieves a list of metafields that belong to a resource. [See the documentation](https://shopify.dev/docs/api/admin-graphql/unstable/queries/metafields)",
1011
version: "0.0.6",
11-
type: "action",
12+
name,
13+
description,
14+
type,
1215
props: {
1316
shopify,
1417
...metafieldActions.props,
15-
...common.props,
18+
namespace: {
19+
type: "string[]",
20+
label: "Namespace",
21+
description: "Filter results by namespace",
22+
optional: true,
23+
},
24+
key: {
25+
type: "string[]",
26+
label: "Key",
27+
description: "Filter results by key",
28+
optional: true,
29+
},
1630
},
1731
methods: {
1832
...metafieldActions.methods,
19-
...common.methods,
33+
},
34+
async additionalProps() {
35+
return this.getOwnerIdProp(this.ownerResource);
36+
},
37+
async run({ $ }) {
38+
let response = await this.listMetafields(this.ownerResource, this.ownerId);
39+
40+
if (this.namespace?.length > 0) {
41+
response = response.filter((field) => this.namespace.includes(field.namespace));
42+
}
43+
44+
if (this.key?.length > 0) {
45+
response = response.filter((field) => this.key.includes(field.key));
46+
}
47+
48+
$.export("$summary", `Found ${response.length} metafield(s) for object with ID ${this.ownerId}`);
49+
return response;
2050
},
2151
};

components/shopify_developer_app/actions/update-metafield/update-metafield.mjs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import metafieldActions from "../common/metafield-actions.mjs";
22
import common from "@pipedream/shopify/actions/update-metafield/update-metafield.mjs";
33
import shopify from "../../shopify_developer_app.app.mjs";
44

5-
import { adjustPropDefinitions } from "../../common/utils.mjs";
6-
75
const {
86
name, description, type, ...others
97
} = common;
10-
const props = adjustPropDefinitions(others.props, shopify);
118

129
export default {
1310
...others,
@@ -18,8 +15,7 @@ export default {
1815
type,
1916
props: {
2017
shopify,
21-
...props,
22-
...common.props,
18+
...metafieldActions.props,
2319
},
2420
async additionalProps() {
2521
const props = await this.getOwnerIdProp(this.ownerResource);
@@ -39,7 +35,6 @@ export default {
3935
},
4036
methods: {
4137
...metafieldActions.methods,
42-
...common.methods,
4338
async getOwnerIdProp(ownerResource) {
4439
const resources = {
4540
product: shopify.propDefinitions.productId,
@@ -62,7 +57,7 @@ export default {
6257

6358
const props = {};
6459

65-
if (ownerResource === "variants" || ownerResource === "product_image") {
60+
if (ownerResource === "variants") {
6661
props.productId = resources.product;
6762
}
6863
if (ownerResource === "article") {

components/shopify_developer_app/common/queries.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const LIST_ORDERS = `
109109
nodes {
110110
id
111111
updatedAt
112-
metafields (first: $first) {
112+
metafields (first: $first, after: $after) {
113113
nodes {
114114
id
115115
key
@@ -119,6 +119,9 @@ const LIST_ORDERS = `
119119
}
120120
}
121121
}
122+
pageInfo {
123+
endCursor
124+
}
122125
}
123126
}
124127
`;
@@ -128,7 +131,7 @@ const LIST_DRAFT_ORDERS = `
128131
draftOrders(first: $first, after: $after) {
129132
nodes {
130133
id
131-
metafields (first: $first) {
134+
metafields (first: $first, after: $after) {
132135
nodes {
133136
id
134137
key
@@ -138,6 +141,9 @@ const LIST_DRAFT_ORDERS = `
138141
}
139142
}
140143
}
144+
pageInfo {
145+
endCursor
146+
}
141147
}
142148
}
143149
`;
@@ -148,7 +154,7 @@ const LIST_CUSTOMERS = `
148154
nodes {
149155
id
150156
displayName
151-
metafields (first: $first) {
157+
metafields (first: $first, after: $after) {
152158
nodes {
153159
id
154160
key
@@ -158,6 +164,9 @@ const LIST_CUSTOMERS = `
158164
}
159165
}
160166
}
167+
pageInfo {
168+
endCursor
169+
}
161170
}
162171
}
163172
`;

components/shopify_developer_app/shopify_developer_app.app.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import commonApp from "@pipedream/shopify";
22
import Shopify from "shopify-api-node";
33
import queries from "./common/queries.mjs";
44
import mutations from "./common/mutations.mjs";
5+
import { API_VERSION } from "@pipedream/shopify/common/constants.mjs";
56

67
export default {
78
...commonApp,
89
type: "app",
910
app: "shopify_developer_app",
1011
propDefinitions: {
12+
...commonApp.propDefinitions,
1113
orderId: {
1214
type: "string",
1315
label: "Order ID",
@@ -111,6 +113,7 @@ export default {
111113
shopName: this.getShopId(),
112114
accessToken: this.$auth.access_token,
113115
autoLimit: true,
116+
apiVersion: API_VERSION,
114117
});
115118
},
116119
getOrder(variables) {

0 commit comments

Comments
 (0)