-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphqlClient.mjs
35 lines (31 loc) · 892 Bytes
/
graphqlClient.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { GraphQLClient, gql } from 'graphql-request'
// set up the GraphQL client that we'll use throughout the app to query Shopify
// for whatever data we need
const client = new GraphQLClient(
`https://${process.env.SHOP}.myshopify.com/admin/api/${process.env.API_VERSION}/graphql.json`,
{
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Shopify-Access-Token': process.env.SHOPIFY_ACCESS_TOKEN,
},
}
)
const addProductTagMutation = gql`
mutation AddProductTag($id: ID!, $tags: [String!]!) {
tagsAdd(id: $id, tags: $tags) {
node {
id
}
userErrors {
message
}
}
}
`
export async function addProductTag(productGid, newTags) {
const addProductTagResult = await client.request(
addProductTagMutation, { id: productGid, tags: newTags }
)
return addProductTagResult
}