I’m new to using GraphQL and was hoping to get some guidnance.
I’ve managed to write to the shop metafields using this query (I’m storing it against the shop as it’s unique to that url, although I did read you can install agains the app installation but couldn’t find any docs on that):
const metaResponse = await admin.graphql(
`#graphql
mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
key
namespace
value
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}`,
{
variables: {
"metafields": [
{
"key": metafieldKey,
"namespace": metafieldNamespace,
"ownerId": shopId,
"type": "single_line_text_field",
"value": apiKey
}
]
},
},
);
Where OwnerID is the shop you’re interacting with in the admin interface.
But then trying to read it back, I can’t figure out the syntax:
const queryData = `
{
shop(ownerId: "` + shopId + `") {
metafield(namespace: "` + metafieldNamespace + `", key: "` + metafieldKey + `") {
id
value
}
}
}
`;
Can anyone help untangle me please.
Thanks
Greg