1

I'm trying to write a GraphQL query which creates matrix blocks. The information in the docs as well as this question didn't help to get it working.

This is what the field settings look like: enter image description here

This is my query:

mutation saveEntry(
    $biography: [biography_MatrixBlockContainerInput]
    $sortOrder: [QueryArgument]
    $info: String
    $authorId: ID
    $siteId: Int
    $title: String
) {
    save_artist_default_Entry(
        biography: { blocks: $biography, sortOrder: $sortOrder }
        info: $info
        authorId: $authorId
        siteId: $siteId
        title: $title
    ) {
        id
        title
        info
    }
}

And here my variables:

{
    "title": "test",
    "info": "info",
    "authorId": 1,
    "siteId": 1,
    "sortOrder": [
        "new1"
    ],
    "biography": [
        {
            "biosection": {
                "sortOrder": "new1",
                "headline": "test",
            }
        }
    ]
}

When using Insomnia (API client) to test the query, I get the following error:

{
    "errors": [
        {
            "message": "craft\\services\\Gql::executeQuery(): Argument #3 ($variables) must be of type ?array, string given, called in /Users/xxx/vendor/craftcms/cms/src/controllers/GraphqlController.php on line 195"
        }
    ]
}

I don't know why it says Argument #3 causes the error. I changed the order but the error message never changes. If I remove the "biography" block from the variables, it works.

1 Answer 1

2

Two things, I see a typo in your variables (extra , after "headline": "test",), and you should be passing an id to the block, not sortOrder (see docs). Try the below as variables and it should work:

{
    "title": "test",
    "info": "info",
    "authorId": 1,
    "siteId": 2,
    "sortOrder": [
        "new1"
    ],
    "biography": [
        {
            "biosection": {
                "id": "new1",
                "headline": "test"
            }
        }
    ]
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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