-
Notifications
You must be signed in to change notification settings - Fork 13
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
[MTKA-1483] Register ACM fields for GraphQL mutations #499
Conversation
This mostly seems to impact test data where graphql_single_name is not set.
When submitted via GraphQL, multiple choice fields are passed as an array of choice keys: [ "choice1", "choice2" ]. When submitted via the publisher form, multiple choice fields are passed as an array of keys and values in the case of a "multi": [ "choice1" => "Choice 1", "choice2" => "Choice 2"]. This commit adjusts the sanize_field logic so that all inputs above result in an output of [ "choice1", "choice2" ] and adds tests to verify that behavior.
Form data for multis is passed as: ( [0] => Array ( [test] => test ) [1] => Array ( [test2] => test2 ) )
Derive model GraphQL name from raw field data instead of registered field data. To work around a timing issue where tests were failing due to GraphQL types being registered in our testing environment before ACM post types were registered.
- Updates correct boolean type. - Removes resolver in mutation registration. The existing resolver logic in register_content_fields_with_graphql handles value resolution.
// When you have multiple items in an array returned we need to define them as a list of strings. | ||
if ( 'list' === $field['type'] ) { | ||
$field['type'] = array( 'list_of' => 'String' ); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated map_html_field_type_to_graphql_field_type
to return the correct type in place of this logic.
The GraphQL mutations logic also needs to grab the type so we may as well return it up front instead of changing it here.
update_post_meta( $post_id, 'boolean', 'off' ); | ||
update_post_meta( $post_id, 'booleanRequired', 'on' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean values are ultimately stored in meta as 'off' or 'on' and not 'true' or 'false' so I changed the tests to reflect that.
* delete operations on ACM models. | ||
* - Document how a delete mutation should work. | ||
*/ | ||
public function test_graphql_delete_mutations_remove_acm_entries(): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can omit this test if needed because it's WPGraphQL and not ACM that registers CPTs for delete mutations. I felt it worthwhile just to confirm and document delete mutation behavior, though.
For consistency with GraphQL responses.
case 'boolean': | ||
return $meta_value === 'on' ? true : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating the REST response for consistency with the GraphQL response for boolean fields, and so that tests pass with the updated test data (which changed to 'on' and 'off' instead of 'true' and 'false').
Update mutations don't seem like they should enforce required fields, as the check for required fields was made during post creation. Users should not have to pass required fields if they are updating another field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left one minor nit/question. Excellent work!
includes/content-registration/custom-post-types-registration.php
Outdated
Show resolved
Hide resolved
@nickcernis there's a merge conflict here now. Sorry about that. |
@mindctrl Fixed, thanks for the note! |
Description
Registers ACM fields for
create[ModelName]
andupdate[ModelName]
GraphQL mutations so that devs can send ACM fields as mutation inputs.Addresses #240.
Note that:
https://wpengine.atlassian.net/browse/MTKA-1359
https://wpengine.atlassian.net/browse/MTKA-1483
Testing
Read the docs introduced by this PR and try making a mutation request against one of your models in GraphiQL:
https://github.com/wpengine/atlas-content-modeler/blob/mtka-1359/mutations/docs/mutations/index.md
Documentation Changes
I added docs to this repo. We could move them to https://developers.wpengine.com/ once we know what release this will be part of.