GraphQL query collection records (relationship) #448
chladog
started this conversation in
Show and tell
Replies: 1 comment
-
@chladog thanks for sharing this snippet! I modified it to make a couple of custom queries. However I noticed that if any of your selections on |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have created new relationship graphql query for easy retrieval of relationship objects based on slug and id (the basic information we get from richtext editor with default depth).
This solves the problem between dynamic nature of relationship fields and explicit grahpql collection queries.
For example we add a relationship in richtext and get this payload:
but it can have relationTo any collection, like "posts" for example.
With default queries you would have to switch case slugs and choose query per collection on client side, which is not very maintainable especially when editing/adding new collections.
Following query finds record in collection based on slug and resolves type dynamically and return the union type of all collections.
Then can be used like:
Might be usefull for different use cases when collection slug is dynamic as well.
Beta Was this translation helpful? Give feedback.
All reactions