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

Feature: Query multiple node types simultaneously #2775

Closed
uttrasey opened this issue Nov 3, 2017 · 6 comments
Closed

Feature: Query multiple node types simultaneously #2775

uttrasey opened this issue Nov 3, 2017 · 6 comments

Comments

@uttrasey
Copy link

uttrasey commented Nov 3, 2017

I'm using the gatsby-source-contentful and would like, in a single query, to be able to order and paginate several content types simultaneously.

The use case for this is a "latest content feed" which co-mingles 3 different content types chronologically based on a publishDate field which I've added to each of the CMS content models.

I've been reading about GraphQL Unions and Interfaces as a means to dealing with different content types collectively.

I'm keen to know if this is achievable and what the best approach is.

@KyleAMathews
Copy link
Contributor

This seems like a really valuable area to explore. There's definitely lots of times you want to query multiple types at once like your "content feed" use case.

A few ways we could handle this:

  • A source plugin creates union/interface types as it makes sense for their data
  • A site builder can manually group types into a new union type
  • We expose a new hook to do this programatically
  • Automatically infer interfaces based on common fields — e.g. all Contentful node types could share a number of fields e.g. your publishDate — it'd be fairly straightforward to infer this and generate a new interface type based on the common fields.

People have any other ideas?

@uttrasey
Copy link
Author

uttrasey commented Nov 6, 2017

I think automatically inferring might be tricky where as allowing programatic union definition would allow for more control / use cases. For example not everything with a publishDate should appear in my "content feed".

Being relatively new to gatsby I don't have a strong feeling on how to expose this functionality hook vs plugin. Thoughts?

@KyleAMathews
Copy link
Contributor

I think automatically inferring might be tricky where as allowing programatic union definition would allow for more control / use cases. For example not everything with a publishDate should appear in my "content feed"

👍 also someone could easily write a plugin to do the automatic inference. Always better to start low-level and manual in core and then experiment with higher-level primitives in userland.

Plugins use hooks so both :-) Probably the best way to land this is to add a PR with the new API hook along with an example site demoing its use and then if there's a really solid plugin that can automate some of this, add that as well.

This would be really exciting functionality to add!

@uttrasey
Copy link
Author

uttrasey commented Nov 8, 2017

Sounds good. I'm going to try and get something raised early next week 👌

@uttrasey
Copy link
Author

Raised something super rough to get feedback #2990

@KyleAMathews
Copy link
Contributor

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

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

No branches or pull requests

2 participants