The ‘owner’ field for the GraphQL Metafield object (https://shopify.dev/api/admin-graphql/2022-01/objects/Metafield) is specified to be the owner resource but implements the HasMetafields interface. We’ve been unable to use this to retrieve the actual ID of the owner resource for a metafield after it has been created. We use the MetafieldsSet mutation to edit or create metafields in which the input data contains an ‘ownerId’ value naturally. But we cannot get this owner ID value to be returned in the results returned from this mutation or from a simple Metafields query.
Can anyone explain and give examples of how this owner field can be used to get the actual owner resource properties? It doesn’t make sense to have this property as a HasMetafields interface if its only use is to retrieve or query other metafields for the owner resource without actually identifying the owner resource itself.
Below are two examples of the MetafieldsSet mutation, the first one works, the others do not of course:
#1: This works, but doesn’t make sense why this HasMetafields interface is here or needed…
mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
id
legacyResourceId
key
namespace
type
value
owner{ metafields(first: 10) { edges { node { namespace }}}}
ownerType
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}
Result (partial):
{
"data": {
"metafieldsSet": {
"metafields": [
{
"id": "gid://shopify/Metafield/20096615677986",
"legacyResourceId": "20096615677986",
"key": "charlap",
"namespace": "blah",
"type": "single_line_text_field",
"value": "Mertert",
"owner": {
"metafields": {
"edges": [
{
"node": {
"namespace": "attributes"
}
},
{
"node": {
"namespace": "blah"
}
},
#2: This doesn’t work, see result error:
mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
id
legacyResourceId
key
namespace
type
value
owner { id }
ownerType
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}
Result (partial):
{
"errors": [
{
"message": "Field 'id' doesn't exist on type 'HasMetafields'",
"locations": [
{
"line": 10,
"column": 15
}
],
#3 also doesn’t work, different error message
mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
id
legacyResourceId
key
namespace
type
value
owner
ownerType
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}
Result (partial):
{
"errors": [
{
"message": "Field must have selections (field 'owner' returns HasMetafields but has no selections. Did you mean 'owner { ... }'?)",
"locations": [
{
"line": 10,
"column": 7
}
],
Can anyone advise if they have found a way to use this owner property to get to the fields for the actual owner resource? Thanks!