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

fix: createComment Mutation not checking for name and email #1849

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

moonmeister
Copy link
Collaborator

@moonmeister moonmeister commented Apr 7, 2021

What does this implement/fix? Explain your changes.

  1. Changed the commentOn type to by ID as it seems it should be. Given this is potentially a breaking change I can revert it if needed.
  2. Modified the Schema to correctly reflect what fields are required. (commentOn was already required in the code but was throwing a error when not provided. the Schema now reflects that.
  3. Check for name/email when they are required in the discussion settings and reflect that change in the schema as appropriate.(previously choosing the option to require name/email didn't affect the ability to submit a comment without name/email).
  4. Modified field description to note they may be required depending on WP Config.

Does this close any currently open issues?

1 partially addresses #997

Any other comments?

I'll try my hand at tests here soon. I'll also see if I should modify related mutations to match.

Where has this been tested?

Operating System:
Linux

WordPress Version:

6.3

'description' => __( 'The ID of the post object the comment belongs to.', 'wp-graphql' ),
],
'author' => [
'type' => 'String',
'type' => boolval( get_option( 'require_name_email' ) ) ? [ 'non_null' => 'String' ] : 'String',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an option can make this nullable, we should probably leave it nullable in the Schema.

Otherwise setting/unsetting this option in the admin would be a breaking change for clients.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't make sense to me, but I may be missing something...

When this option is enabled on the server any mutations not passing this data will start breaking either way, right?. The only difference is whether it's a schema error or a server error (not sure if those are the correct terms 🤷 ). If this remains, then when this option is enabled the schema will correctly indicate to devs what the server requires, which seems extremely helpful.

If this option is disabled, It can still accept name/email but it isn't required...i don't see what would break...am I missing something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moonmeister the difference as I see it is that a schema change can break the frontend (possibly even preventing it from compiling) whereas if it fails validation on the server, an existing frontend will just handle it like any other error response.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally if someone flips that switch and causes something to break I'd rather my build break than finding out in production.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, We don't want to change this. Keep in nullable

@stale
Copy link

stale bot commented Aug 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 2, 2022
@justlevine justlevine added the Compat: Breaking Change This is a breaking change to existing functionality label Sep 24, 2022
@stale
Copy link

stale bot commented Dec 24, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale? May need to be revalidated due to prolonged inactivity label Dec 24, 2022
@moonmeister moonmeister added not stale Short-circuits stalebot. USE SPARINGLY and removed Stale? May need to be revalidated due to prolonged inactivity stale labels Dec 24, 2022
@moonmeister
Copy link
Collaborator Author

We can add a verbose description. Including a descriptive part that can switch based on current setting.

Copy link
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just to make the status change more visible)

@justlevine justlevine added Type: Enhancement New feature or request Status: In Progress Component: Mutations and removed Compat: Breaking Change This is a breaking change to existing functionality not stale Short-circuits stalebot. USE SPARINGLY labels Oct 9, 2023
@moonmeister moonmeister changed the title fix: various issues on createComment Mutation fix: createComment Mutation not checking for name and email Oct 10, 2023
@moonmeister
Copy link
Collaborator Author

@justlevine Got this updated. Looks like I might need to format. Otherwise, we should probably add tests. I can try, just point me in the right direction.

@codeclimate
Copy link

codeclimate bot commented Oct 10, 2023

Code Climate has analyzed commit befd0dc and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@justlevine justlevine self-requested a review October 10, 2023 13:45
Copy link
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the conditional logic so it only applies to unauthenticated users. Also added tests for this and expanded the existing ones to cover unauthenticated cases.

Theres one case failing somewhere upstream that I've been unable to track 🤔 Could use some help.


$variables['email'] = null;

$actual = $this->graphql( compact( 'query', 'variables' ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query is throwing the following GraphQL error, but i've been unable to trace what is requesting that array key, or why it would be a fatal error instead of a PHP warning:

image

(removing comment from the query entirely passes, so I'm guessing it's something on the CommentModel ).

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

Successfully merging this pull request may close these issues.

None yet

3 participants