graphqlcraftcms

For Craft CMS, how do I include a category and asset in a GraphQL entry mutation?


I have been stuck on a mutation graphql query in Craft CMS for an entry. This entry I am trying to create includes a category and asset property. I am not sure how to get the category type or asset type and create it in the entry. I would love some help on this as I cannot find any examples for this from the Craft documentation. Here is my query below:

mutation SaveCreation($title: String, $slug: String, $creationProductType: ???(category), $creationImage: ???) {
  save_creations_creations_Entry(title: $title, slug: $slug, creationProductType: ???, creationImage: ???) {
    title
    slug
    creationProductType
    creationImage
    dateCreated @formatDateTime(format: "Y-m-d")
  }
}


{
  "title": "Supports GraphQL Mutations",
  "slug": "supports-mutations",
  "creationProductType": 8971(this is the id of category but do not know if this is correct??),
  "creationImage": {
    "title": "practice image",
    "url": "https://imgur.com/123asfgfgfdg"
   }
}

Solution

  • Ok so this seemed to work:

    mutation SaveCreation($title: String, $creationProductType: [Int], $creationImage: [Int]) {
      save_creations_creations_Entry(title: $title, creationProductType: $creationProductType, creationImage: $creationImage) {
        title
        creationProductType {
          id
        }
        creationImage {
          id
        }
        dateCreated @formatDateTime(format: "Y-m-d")
      }
    }
    
    {
      "title": "Another Practice dummy",
      "creationProductType": 25800,
      "creationImage": 980
    }