4

I know how to update simple fields on an entry using a mutation:

mutation updateRecipe($recipeId: ID, $slug: String) {
  save_recipes_recipe_Entry(id: $recipeId, slug: $slug) {
    id
    title
    slug
  }
}
Variables:
{
  "recipeId": 8614,
  "slug":"new-slug"
}

Is there a way to append a block to a Neo field using mutations? I can retrieve the field data in a GraphQL query but have not found a way to update a Neo field with a mutation.

Does anybody have any experience implementing this?

Thanks ...

4

So the work around was to convert the Neo field to a Matrix. That worked for this instance since we're not storing anything complex but I'd sure like to figure out if/how Neo supports mutations.

mutation addRecipeReview($recipeId: ID, $blocks: [reviews_MatrixBlockContainerInput] = {review: {authorEmail: "", authorName: "", authorReview: "", reviewDate: "", reviewRating: ""}}, $sortOrder: [QueryArgument] = "") {
  save_recipes_recipe_Entry(id: $recipeId, reviews: {blocks: $blocks, sortOrder: $sortOrder}) {
    id
    reviews {
      ... on reviews_review_BlockType {
        id
        authorEmail
        authorName
        authorReview
        reviewRating
        reviewDate
      }
    }
  }
}

Variables:
{
  id: "1234",
  sortOrder: ["4321", "4322", "new:1"],
  blocks: [
    {
      review: {
        authorName: "Author Name",
        authorEmail: "Author Email",
        authorReview: "Review",
        reviewRating: "Rating",
        reviewDate: "Date Submitted"
      }
    }
  ]
}

The odd/silly part about the above is that you have to pass in an array of all the existing block IDs to sortOrder, and use the idiom "new:1" for your new block. If you skip the "new:1" it won't add the new block, and if you only pass in "new:1" but omit the existing block IDs it deletes all the existing blocks. You can pass an array of new blocks (the code above only has one) in the 'blocks' array, but you'll have to add "new:1", "new:2" ... up to how many blocks you have.

2
  • This is the only working example of a matrix mutation I've been able to find. Thank you for posting! Dec 29 '20 at 0:26
  • Snap! thanks Jon
    – magicspon
    Mar 3 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.