craftcms / craftcms/cms

[4.x]: GraphQL mutation: "We couldn't find any matching entries" when creating entry with relational fields

Open
#14,801 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug craft4
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

When trying to create an entry with relational fields via a GraphQL Mutation, I got the message "We couldn't find any matching entries". It seems that the corresponding relational entry doesn't exist. But it does definitely.

When updating the entry (while passing the entryID to the mutation), it updates the relational field with the corresponding entry.

The strange thing is that it's working in graphiQL when passing all the necessary arguments except the entryID, but not in local. We also checked all the necessary permissions both in the schema and the user.

Steps to reproduce
  1. Create a mutation that saves an entry
mutation saveOffer(
    $id: ID,
    $title: String,
    $activityIds: [Int]
  ) {
    save_offer_default_Entry(
      id: $id,
      title: $title,
      activity: $activityIds
    ) {
      id
      title
      activity {
        ...on activity_default_Entry {
          id
          title
        }
      }
    }
  }
  1. Call this mutation from the front end while creating a new Offer
const { data, errors } = await saveOfferMutation(authCookie, {
  title: 'test offer',
  activityIds: [121183]
});

=> message: "We couldn't find any matching entries",

  1. Call this same method for updating an offer :
const { data, errors } = await saveOfferMutation(authCookie, {
  id: '121533',
  title: 'test offer',
  activityIds: [121183]
}); 

=> Works perfectly.

Expected behavior

Mutation to create an entry with relational fields while passing the relational field ID to work.

Actual behavior

Not working.

Thanks guys!

Craft CMS version

Craft Pro 4.8.9

PHP version

8.1.27

Operating system and version

Linux 4.19.0-22-cloud-amd64

Database type and version

MariaDB 10.4.33

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.10-23)

Installed plugins and versions

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the save_offer_default_Entry GraphQL mutation from the issue against Craft CMS 4.8.9, comparing creation with the working update case and the frontend saveOfferMutation call. Trace the relational-field ID handling and verify that creating an entry with activityIds succeeds without the matching-entries error.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, php
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.