1

In Craft 3 I am trying to use GraphQL to mutate an existing entry in the section PersonEvents.

Here is what I have in PHP

$mutation = <<<QUERY
mutation saveEntry(\$id: ID, \$avatarUrls: String) {
  save_personEvents_default_Entry(id: \$id, avatarUrls: \$avatarUrls) {
    id
    avatarUrls
  }
}
QUERY;

$variables = <<<VARIABLES
{
  "id": "$personEventId",
  "avatarUrls": "$avatarUrlsString"
}
VARIABLES;

If it is important, avatarUrls is a table field and I'm sending in a string like "[{col1:\"\/svgavatars\/ready-avatars\/svgA013650824185873711.png\"}]".

What I get back is

{
    "errors": [
        {
            "message": "Cannot query field \"save_personEvents_default_Entry\" on type \"Mutation\".",
            "extensions": {
                "category": "graphql"
            },
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ]
        }
    ]
}

I am looking at documentation at https://craftcms.com/docs/3.x/graphql.html#mutations and searching the web for clues and still feel like I'm missing something elementary.

Any ideas to point me in the right direction would be greatly appreciated! Thanks!

=== additional info ===

If I run this in GraphiQL it works, saving the avatarUrls data:

mutation saveEntry {
  save_personEvents_default_Entry(
    id: "1939"
    avatarUrls: [{col1:"/svgavatars/ready-avatars/svgA326319731994384-2.png"}]
  ) {
    id
  }
}

... but if I try a file_get_contents in PHP with query set as that string I get back

{
    "errors": [
        {
            "message": "GraphQL\\Type\\Definition\\Type::getNullableType(): Argument #1 ($type) must be of type GraphQL\\Type\\Definition\\Type, null given, called in [redacted]\/vendor\/webonyx\/graphql-php\/src\/Validator\/Rules\/ValuesOfCorrectType.php on line 75"
        }
    ]
}

What am I missing?

2
  • When no one answers I never know if it's because I didn't provide enough detail, wasn't courteous enough, "should" know the answer, didn't provide enough evidence of putting in work before asking, or something else. If something is getting in the way of anyone answering, please educate me about how to ask in a better way! Jan 30, 2023 at 18:54
  • Added some more info to the question. Feb 1, 2023 at 19:05

1 Answer 1

1

Just in case this helps someone I finally determined that my GraphQL Schema did not have the appropriate Mutations available/enabled in the Craft admin panel. In this case the mutation that allows for creating an entry in that particular section.

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.