Skip to content

Comments

Return mutation result as entity object#2612

Merged
alanpoulain merged 8 commits intoapi-platform:2.4from
whatwedo:gql-wrap-mutation-object
Mar 22, 2019
Merged

Return mutation result as entity object#2612
alanpoulain merged 8 commits intoapi-platform:2.4from
whatwedo:gql-wrap-mutation-object

Conversation

@lukasluecke
Copy link
Contributor

@lukasluecke lukasluecke commented Mar 13, 2019

Q A
Bug fix? yes
New feature? no
BC breaks? yes
Deprecations? no
Tests pass? yes (modified!)
Fixed tickets #2605
License MIT
Doc PR -

See #2605 for details.

@lukasluecke lukasluecke force-pushed the gql-wrap-mutation-object branch 3 times, most recently from 220c2c5 to ac82326 Compare March 13, 2019 14:52
@lukasluecke
Copy link
Contributor Author

lukasluecke commented Mar 13, 2019

@alanpoulain Currently breaks custom normalization_context for specific mutations - see failing Behat test.

Since we are now re-using the same GraphQL-type, I don't think we can add the fields dynamically. Any ideas?


I think it might make sense to not allow setting a normalization context on the mutations, and just using the one set on the entity / query.

@lukasluecke lukasluecke force-pushed the gql-wrap-mutation-object branch from ac82326 to a4b000c Compare March 14, 2019 09:34
@lukasluecke
Copy link
Contributor Author

@alanpoulain I have modified the failing test, but need some input on wether or not this should be the "correct" behaviour.

@lukasluecke lukasluecke marked this pull request as ready for review March 18, 2019 13:10
@alanpoulain
Copy link
Member

@lukasluecke I've done some modifications to handle delete like the other mutations (I've changed my mind about it sorry), to manage the normalization context correctly and I've fixed some latent issues. I will push these modifications to your branch today I hope, if you're okay with that.

@lukasluecke
Copy link
Contributor Author

@alanpoulain Sure, no problem at all 🙂

@alanpoulain alanpoulain force-pushed the gql-wrap-mutation-object branch from 84f3d10 to 41829f9 Compare March 21, 2019 13:34
@alanpoulain
Copy link
Member

Done. The changes:

  • new types to handle different normalization contexts: PayloadData (the object inside the output of a mutation) and NestedPayload (when there is a relation in a PayloadData).
  • the input / output behavior has been changed (@soyuka if you can validate): when there is no output, it's not possible schema-wise to query any field; when there is no input it's not possible schema-wise to add field in the input (but you can give it an empty input with or without a clientMutationId, in this case there is a null response for the output object and no persist is done).
  • the depth issue has been fixed (its value was strange before because it was inside a loop)

@lukasluecke please tell me if you are okay with the changes 🙂

@alanpoulain alanpoulain requested a review from dunglas March 21, 2019 14:08
@lukasluecke
Copy link
Contributor Author

@alanpoulain I fear that adding these new wrapper types might lead back to the original issue, because the __typename of the returned objects will be different.

Apollo client, which is afaik the most popular JS client, would not "match" this for caching purposes

By default, InMemoryCache will attempt to use the commonly found primary keys of id and _id for the unique identifier if they exist along with __typename on an object
https://www.apollographql.com/docs/react/advanced/caching.html

The Relay spec is not totally clear about this, but from my understanding it also expects the "real" type (and full object) to get returned, not just a "similar" object.

Which lead me to my earlier comment:

I think it might make sense to not allow setting a normalization context on the mutations

I'll leave this decision up to you, but personally I'd prefer ease of use over the marginal flexibility.

@lukasluecke
Copy link
Contributor Author

lukasluecke commented Mar 21, 2019 via email

@alanpoulain
Copy link
Member

I deleted my previous comment because it was wrong indeed. Maybe a solution would be to change the type only if the normalization context is different. WDYT?

@lukasluecke
Copy link
Contributor Author

I think that's a good idea! 👍 If you have time to make the changes, I'd appreciate it - otherwise I'll try to squeeze them in next week 🙂

We should also __typename to the Behat test queries to make sure this is enforced.

@alanpoulain
Copy link
Member

Done 🙂

@alanpoulain alanpoulain force-pushed the gql-wrap-mutation-object branch from 19e1751 to dddc321 Compare March 21, 2019 21:34
@alanpoulain alanpoulain force-pushed the gql-wrap-mutation-object branch from dddc321 to 3a1b1fb Compare March 22, 2019 09:43
@alanpoulain alanpoulain merged commit 50fcb9a into api-platform:2.4 Mar 22, 2019
@alanpoulain
Copy link
Member

Thank you @lukasluecke!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants