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

GraphQL: Nested Collections #6038

Merged
merged 2 commits into from
Dec 29, 2023
Merged

GraphQL: Nested Collections #6038

merged 2 commits into from
Dec 29, 2023

Conversation

jotwea
Copy link
Contributor

@jotwea jotwea commented Dec 12, 2023

Q A
Branch? main
Tickets -
License MIT
Doc PR -

We sometimes use JSON arrays to persist a collection of Value Objects which are not an entity. So this collection should be treated like a property of the parent entity. On the GraphQL queries fetching this collection was not an easy task. We had to create some special resolvers which try to fetch the ID of the parent entity out of the $context, load it and determine the collection from there.

So I decided to spend this PR that utilizes the nested property of the ApiProperty and uses the collection already loaded with the entity when no own resolver is given. I added a Behat test that covers that new scenario.

Copy link
Member

@soyuka soyuka left a comment

Choose a reason for hiding this comment

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

needs #6032 to run the CI

@jotwea jotwea force-pushed the graphql-nested branch 2 times, most recently from 4a56dce to 5adc973 Compare December 14, 2023 08:17
@jotwea
Copy link
Contributor Author

jotwea commented Dec 14, 2023

needs #6032 to run the CI

Updated the PR. Still some jobs fail because of deprecations, but this is not related to the changes in this PR. Maybe it can be merged anyway

@alanpoulain
Copy link
Member

In my opinion, since it's a collection it should follow the Relay specification and have edges and nodes.

@jotwea
Copy link
Contributor Author

jotwea commented Dec 19, 2023

In my opinion, since it's a collection it should follow the Relay specification and have edges and nodes.

Works now. Can be controlled via paginationEnabled flag

@alanpoulain
Copy link
Member

Nice, maybe could you add one case with the pagination enabled too?

@jotwea
Copy link
Contributor Author

jotwea commented Dec 20, 2023

Nice, maybe could you add one case with the pagination enabled too?

Updated the tests. We now have nested collection with and without pagination enabled.

@jotwea jotwea force-pushed the graphql-nested branch 2 times, most recently from abab343 to 899ac0a Compare December 20, 2023 18:25
@soyuka
Copy link
Member

soyuka commented Dec 29, 2023

I'll solve phpstan in another patch thanks @jotwea @alanpoulain !

It'd be nice to document this behavior now.

@soyuka soyuka merged commit 82b702d into api-platform:main Dec 29, 2023
48 of 55 checks passed
priyadi pushed a commit to priyadi/core that referenced this pull request Jan 3, 2024
* feat(graphql): support nested collections

* null safe operator

---------

Co-authored-by: josef.wagner <[email protected]>
Co-authored-by: Antoine Bluchet <[email protected]>
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.

3 participants