-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Can Route queries only go one level deep? #456
Comments
The essential (and only) function that they serve right now is to anchor a The beauty of containers is that they can be composed anywhere, and they don't need to "know" anything about where they will be placed. But we need a route (or "query config" if you prefer) to turn these independent fragments that don't make sense in isolation into something that we can actually send to GraphQL to be executed. |
If Instead of writing a container that depends on a route, like: export default Relay.createContainer(WidgetList, {
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
widgets(first: 10) {
edges {
node {
id,
name,
},
},
},
}
`,
},
}); What if we could write a container that can stand on its own, like this: export default Relay.createContainer(WidgetList, {
fragments: {
query: () => Relay.QL`
fragment on Query {
viewer {
widgets(first: 10) {
edges {
node {
id,
name,
},
},
},
}
}
`,
},
}); or like this: export default Relay.createContainer(WidgetList, {
query: () => Relay.QL`
query {
viewer {
widgets(first: 10) {
edges {
node {
id,
name,
},
},
},
}
}
`,
}); My first experiences with Relay were very frustrating, mostly because I couldn't figure out how I was supposed to split up my GraphQL query between a There is a real lack of testable examples in the documentation right now, partly because you have to understand how to assemble a |
@nickretallack You are absolutely right, and I think there is a good chance we //will// get rid of There are a few things currently in progress that are getting us closer to this:
|
Cool. I hope you do make |
Relay special cases |
Oh. Maybe I'm mistaken, but when I tried it that did not work. If I fetched a list of things, then tried to fetch the individual thing through nodes it would work without performing another query, while fetching it through some other field it would. Maybe you need to do something special to annotate this field as cacheable? |
Ran into this same issue before realizing I should have checked here a long time ago! Lo and behold. Thing about this issue is that the documentation encourages you to think that For example, on the Routes guide, you get this whole thing about how you can make a
No mention in the Route API reference either. Given the the docs stress this so hard, I was so fully sold on this that I wasted at least an hour trying to figure out what was wrong with my code! Not posting on #112 or #503 to avoid polluting those issues, but would be great if |
I mean, if |
@dminkovsky I'm sorry to hear that this was frustrating. You raise good points about the tradeoff of nesting fields in the query vs container. Rather than allow more nesting within route queries, we'd like to go in the opposite direction: eliminating the need for routes & their queries, and instead allow express data dependencies solely via containers. @steveluscher is building the prerequisite to this in #112, which adds support for arbitrary root fields. |
@josephsavona Oh no, please—thank you for Relay in general and your work here on GitHub. Really appreciate both! Was less expressing frustration and more providing feedback regarding confusion caused by the docs. If you are planning to eliminate routes and their queries, then all compositing will be done via containers? Got to read #112... :) Thanks again |
I mean, that |
I tried to write a more complex query in my route. It didn't work.
Can these queries only go one level deep? Why is this restricted? I already have to give up one level to get out of the one-argument-only restriction or to use connections, which makes these routes pretty useless. The only time I wouldn't want it to be exactly
query {viewer}
is if I wanted it to bequery { node( id: $id ) }
instead, because that's the only way I've seen to get Relay to look at its caches.Anyway, it would be nice if I could put something more complex in the route here. Especially when I'm using react-router-relay. Otherwise I need to create a bunch of wrapper components just to pick up the slack because the queries argument won't do anything for me.
The text was updated successfully, but these errors were encountered: