Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: GraphQL mutation "Author Id cannot be blank." #11312

Closed
ardin0546 opened this issue May 25, 2022 · 6 comments
Closed

[4.x]: GraphQL mutation "Author Id cannot be blank." #11312

ardin0546 opened this issue May 25, 2022 · 6 comments

Comments

@ardin0546
Copy link
Contributor

What happened?

Description

I created a very basic entry named posts. The type of the entry is channel and it only has one basic field named title.
With GrapQL I am trying to insert a single post entry. When I do this outside craft (for example with postman) I get the error message Author Id cannot be blank..

This is the query what I'm trying to execute. User 21 exists in the database.
Schermafbeelding 2022-05-25 om 11 31 26

I checked also the following in my Public schema:
Schermafbeelding 2022-05-25 om 11 26 17

I also tried with a private schema and a Bearer token and then my error message is Cannot query field \"authorId\" on type \"posts_default_Entry\".

However, when I'm doing the exact same query in the GraphQL Explorer inside craft, I am able to create a post. Only the authorId is not set to the expected 21 (normal user). But to my current session user 1 (admin user).

Query:
Schermafbeelding 2022-05-25 om 11 34 51

Result:
Schermafbeelding 2022-05-25 om 11 35 41

And in the docs it's written that I am able to send authorId as parameter.

Steps to reproduce

  1. Upgrade craft to a PRO trial license
  2. Create a new section. Title: Posts, handle: posts, Section type: channel, Now the section has a Default entry type and a default field title.
  3. Under GraphQL -> Schemas -> Plublic Schema -> Choose the available mutations for this schema, check everything related to Section - posts
  4. In your config/routes.php add: 'api' => 'graphql/api',
  5. Create a POST request with for example postman and execute the query from the description to endpoint {yourSite}/api

Expected behavior

A post is created with that authorId

Actual behavior

Error message: Author Id cannot be blank. or Cannot query field \"authorId\" on type \"posts_default_Entry\".

Craft CMS version

4.0.3

PHP version

8.0.19

Operating system and version

Darwin 20.1.0

Database type and version

MySQL 8.0.29

Image driver and version

GD 8.0.19

Installed plugins and versions

No response

@brandonkelly
Copy link
Member

The issue is most likely that you are trying to return the resulting entry’s authorId, which is only available if your schema includes UsersView all users. Without that, no user-related info will be available.

@ardin0546
Copy link
Contributor Author

ardin0546 commented May 30, 2022

Nope, Users → View all users was also set...

I had to create a custom plugin to set an authorId on the element as workaround.

Everything with retrieving data works fine (including authorId), everything with mutating requires me the authorId. When I send it as parameter I get an error.

@brandonkelly
Copy link
Member

Sorry, looked into it again using an external GraphQL IDE and was able to reproduce. Fixed now for the next release!

@stuible
Copy link

stuible commented Jun 1, 2022

Thanks a ton for fixing this so quickly, Is there an ETA for this next release?

@brandonkelly
Copy link
Member

Should be imminent.

@brandonkelly
Copy link
Member

Craft 4.0.4 is out now with that fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants