Re: [GraphQL MetafieldDefinition] How to get whether a metafield allows multiple values ​​or not by

Solved

[GraphQL MetafieldDefinition] How to get whether a metafield allows multiple values ​​or not by API

ttpp
Shopify Partner
4 0 1

We can choose single/multiple values values in a single metafield when add a metafield definition.

I'd like to get whether the metafield allows multiple values ​​or not by GraphQL MetafieldDefinition API.

I tried query like this

query {
metafieldDefinitions(first: 10, ownerType: ORDER) {
edges {
node {
id
key
namespace
name
metafieldsCount
type {
category
}
}
}
}
}

and the response was

"node": {
"id": "gid://shopify/MetafieldDefinition/786366676",
"key": "_int_array",
"namespace": "custom",
"name": "整数のリスト",
"metafieldsCount": 1,
"type": {
"category": "NUMBER"
}
}
},

 

How can I get any information of it's single or multiplue?

Accepted Solution (1)

danloomer
Shopify Staff
11 5 4

This is an accepted solution.

Hello @ttpp  👋

 

Your best bet is to query the name of the type and check that it starts with "list."

 

query Definition {
  metafieldDefinitions(first: 10, ownerType: ORDER) {
    edges {
      node {
        type {
          name
        }
      }
    }
  }
}

 

This prefix is consistently used for all types that support a list of values. 

 

 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 2 (2)

danloomer
Shopify Staff
11 5 4

This is an accepted solution.

Hello @ttpp  👋

 

Your best bet is to query the name of the type and check that it starts with "list."

 

query Definition {
  metafieldDefinitions(first: 10, ownerType: ORDER) {
    edges {
      node {
        type {
          name
        }
      }
    }
  }
}

 

This prefix is consistently used for all types that support a list of values. 

 

 

To learn more visit the Shopify Help Center or the Community Blog.

ttpp
Shopify Partner
4 0 1

This problem was resolved thanks to your support!