0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Shopify] GraphqlAPIでmetafieldsにメディアを新しくアップロードする

Posted at

metafieldsにあるfile_referenceに新しくファイルをアップロードしたい人向けの備忘録

前提

  • ファイルを既にどこかS3とかに置いておいて、外向きのURLを取得しておいてあること

クエリ

mutation fileCreate($files: [FileCreateInput!]!) {
  fileCreate(files: $files) {
    files {
      ... on MediaImage {
        id
      }
    }
    userErrors {
      message
    }
  }
}

解説

fileCreateは[File]を返す一方で、metafieldsはMediaImageを要求する。
MediaImageはFileをimplementsしているため、こんな感じでクエリを書くことでMediaImageのIDがもらえる。

参考

https://shopify.dev/docs/api/admin-graphql/2023-01/mutations/fileCreate
https://shopify.dev/docs/api/storefront/2023-01/objects/MediaImage

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?