-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Idea: flatten arrays of fragments when querying #421
Comments
I thought it already did this, or at least that was definitely the intention. Could you PR a failing test case for this? Then @Poincare should look at it. |
Yup! Probably won't get around to that for a few days though |
OK we will hopefully get to it before then. |
@Poincare wait.. I just realized your test tests something totally different. Can you write a test where you pass an array of fragments into |
Ah, yeah, sorry, the case is more like this: it('should accepted nested arrays of fragment defs', () => {
const fragmentDoc1 = gql`
fragment authorDetails on Author {
firstName
lastName
...otherAuthorDetails
}`;
const fragmentDoc2 = gql`
fragment otherAuthorDetails on Author {
address
}`;
const fragmentDoc3 = gql`
fragment evenMoreAuthorDetails on Auth {
rating
}`;
const fragments2 = createFragment(fragmentDoc2);
const fragments3 = createFragment(fragmentDoc3);
const fragments1 = createFragment(fragmentDoc1, [fragments2, fragments3]);
assert.equal(fragments2.length, 1);
assert.equal(fragments3.length, 1);
assert.equal(fragments1.length, 3);
}); |
So, I was assuming that the way you would declare a dependency between I guess if we want to make it so that app developers can just group together fragments by creating nested arrays, I can add array flattening to |
@Poincare I think you should be able to create a fragment that has a dependency on multiple other fragments - how would you do that without this nested array approach? I would definitely expect @nevir's approach to work. Also, can't we just add one more level of possible nesting? I don't think it has to be arbitrary, just one more level. |
So, we could do dependencies on other fragments by doing this:
This declares a dependency between I think the key distinction is that the approach without any nesting, it is clear I'm fine with both approaches. We should probably do whichever is easier to use at the view layer level. |
@Poincare I'd really like to do the nested array approach - that seems the most natural to me, rather than having to call createFragment multiple times. |
Sweet, thanks for the quick turnaround! |
Is this still implemented somehow in v3? Not finding this functionality anywhere, including the babel transforms etc. |
Because
createFragment
returns an array of fragments, you've got to be a bit careful when passing around its result - particularly when you're composing several fragments together:For this sort of situation, it'd be helpful if
createFragment
andquery
flattened out any nested arrays ofFragmentDefinition
s they gotThe text was updated successfully, but these errors were encountered: