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

feat: add spread embeds #2564

Merged
merged 2 commits into from
Nov 17, 2022
Merged

Conversation

steve-chavez
Copy link
Member

@steve-chavez steve-chavez commented Nov 9, 2022

Allows unnesting json objects. Closes #1233.

Instead of getting

GET /grandchild_entities?select=name,child_entities(parent_name:name,entities(grandparent_name:name))&limit=3'

[
{"name":"grandchild entity 1","child_entities":{"parent_name":"child entity 1","entities":{"grandparent_name":"entity 1"}}},
{"name":"grandchild entity 2","child_entities":{"parent_name":"child entity 1","entities":{"grandparent_name":"entity 1"}}},
{"name":"grandchild entity 3","child_entities":{"parent_name":"child entity 2","entities":{"grandparent_name":"entity 1"}}}
]

You can get

GET /grandchild_entities?select=name,..child_entities(parent_name:name,..entities(grandparent_name:name))&limit=3

[
{"name":"grandchild entity 1","parent_name":"child entity 1","grandparent_name":"entity 1"},
{"name":"grandchild entity 2","parent_name":"child entity 1","grandparent_name":"entity 1"},
{"name":"grandchild entity 3","parent_name":"child entity 2","grandparent_name":"entity 1"}
]

Only for many-to-one and one-to-one relationships.

Tasks

  • Initial implementation and test
  • Refactor - DRY
  • Validate to-one relationship
  • More tests

@wolfgangwalther
Copy link
Member

GET /grandchild_entities?select=name,...child_entities(parent_name:name,...entities(grandparent_name:name))&limit=3

Do we need ... or would two dots be enough?

GET /grandchild_entities?select=name,..child_entities(parent_name:name,..entities(grandparent_name:name))&limit=3

@steve-chavez
Copy link
Member Author

I was reusing this syntax https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

But two dots seems fine.

@steve-chavez steve-chavez force-pushed the spread-embeds branch 2 times, most recently from 3e66eeb to 14f547a Compare November 11, 2022 22:37
@steve-chavez steve-chavez marked this pull request as ready for review November 11, 2022 22:37
@steve-chavez
Copy link
Member Author

The spread operator(...) is even used in GraphQL here: https://spec.graphql.org/June2018/#sec-Language.Fragments.

But two dots seems fine.

I think it would be better to keep that syntax since it's already a popular convention, so will go back to 3 dots in another PR.

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

Successfully merging this pull request may close these issues.

Multiple "hops" for embed(Unnest/flatten embeds)
3 participants