-
Notifications
You must be signed in to change notification settings - Fork 0
We *could* pass queries as context #25
Comments
So this isn't documented yet particularly but Gatsby uses the "Modern Relay" compiler which means we inherit their query composition model as well. Basically components (not page ones) can declare query fragments into a global namespace which then other queries can include. So Page A has components A1, A2, and A3, each with their own fragments. If a user ejects A3 and modifies the query, those modifications are automatically included in Page A's query and the resulting data is passed to the ejected A3. Pretty neat eh! An example from Gatsbygram, the Avatar component query (https:/gatsbyjs/gatsby/blob/1.0/examples/gatsbygram/src/components/Avatar.js#L43) is spread into https:/gatsbyjs/gatsby/blob/1.0/examples/gatsbygram/src/pages/index.js#L205 |
Woah that's awesome! It gives you so much control on from the component level. Super excited to try it. |
Hey @KyleAMathews, I tried this out but I'm not having much luck, I basically just get |
Side note: These pages are created by a plugin and are not required from |
Hmmm that's exactly the problem. Right now the relay compiler scans for grapqhl queries and fragments for all js files in "src" as well as any page component. But non-page components like "ChangelogEntry", it has no way of knowing that it's there atm. Hmmm this is tricky. We don't want to just scan node_modules cause it's huge. Perhaps npm Gatsby components could declare their components so our relay compiler implementation can add them to the scan list. They'd also need to ship an es6 version so the template literals aren't compiled away. |
That sounds like the good approach, would that be apart of the |
No I think it'd make the most sense to put this in their package.json. E.g. in a Then at startup, Gatsby could scan the package.json of each dependency to see if it has a |
But yeah, please create an issue on Gatsby and let's discuss some more options there. I have several generic Gatsby components in mind so this would be good to sort out. |
Had an idea, to make things potentially more modular and easy to use.
Currently the page component is responsible for querying the graphql data and passing those props to the child components.
However, we could require the queries which would make them ejectable.
Though that alone isn't helpful as you still need to pass the new query results to child components, so we could pass all queries data as context (context is passed to all child components). This would allow users to just eject the query and the component and not the page, and have vastly different data sent in their child components without having to eject the page.
Down side is that context is not very popular and maybe not a best practice?
The text was updated successfully, but these errors were encountered: