cms icon indicating copy to clipboard operation
cms copied to clipboard

Cannot create entries in multiple sites with graphql

Open Zwartpet opened this issue 4 years ago • 2 comments

Description

Its not possible to create entries in multiple sites through the graphql api. Even though the docs say:

Determines which site(s) the elements should be saved to. Defaults to the primary site.

The api doesn't accept an array with id's.

Steps to reproduce

  1. Create mutation
mutation {
  save_products_flavors_Entry(
    title: "Example"
    siteId: [1, 2]
  ) { id }
}

Additional info

  • Craft version: 3.7.19
  • PHP version: 7.4
  • Database driver & version: Mysql:8

Zwartpet avatar Dec 09 '21 10:12 Zwartpet

Tried a different way:

mutation Mutation1 {
  save_edition_edition_Entry(title: "Test multisite create 2", description:"lasd", siteId: 2) {
    id
  }
}

mutation Mutation2 {
  save_edition_edition_Entry(id: 3340, siteId: 3) {
    id
  }
}

Id in the second mutation is the one from the 1st, but the second mutation throws an error:

{
  "errors": [
    {
      "message": "No such entry exists",
      "extensions": {
        "category": "graphql"
      }
    }
  ],
  "data": {
    "save_edition_edition_Entry": null
  }
}

Zwartpet avatar Dec 09 '21 10:12 Zwartpet

I just fixed the description for the siteId argument - it's a mistake and you can't save an entry to more than two sites at the same time.

Even more, Craft will propagate the entry to other sites for you - you shouldn't save them to other sites yourself.

andris-sevcenko avatar Mar 31 '22 08:03 andris-sevcenko