-
Notifications
You must be signed in to change notification settings - Fork 178
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
Add support for circular dependencies using thunks #199
base: master
Are you sure you want to change the base?
Add support for circular dependencies using thunks #199
Conversation
When colocating fragments, circular dependencies often become an issue. While GraphQL doesn't support circular fragment dependencies, it is still possible to have circular dependencies in the component files that declare the fragments. An example of this is when rendering a tree structure using GraphQL. While GraphQL doesn't allow for recursive queries, it is still possible to query an array of descendants and build a tree data structure in the client. This data structure can then be rendered recursively with React.
@migueloller: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
@migueloller it'd be useful to see a concrete example of how / what this changes — it's unclear to me when this logic would get applied |
@jnwng, something like this: // file1.js
import { Fragment2 } from './file2.js'
import { Fragment3 } from './file2.js'
export const Fragment1 = () => gql`
fragment Fragment1 on SomeType {
field
...Fragment2
...Fragment3
}
${Fragment2}
${Fragment3}
`
// file2.js
import { Fragment1 } from './file1.js'
import { Fragment3 } from './file2.js'
const SomeQuery = gql`
query SomeQuery {
foo {
...Fragment1
}
}
${Fragment1}
`
export const Fragment2 = () => gql`
fragment Fragment2 on SomeType {
field
...Fragment3
}
${Fragment1}
${Fragment3}
`
// file3.js
export const Fragment3 = gql`
fragment Fragment2 on SomeType {
field
}
` Note that I could've also exported the fragment statically and put the thunk in the interpolation. The main idea is that interpolating in type Thunk<T> = () => T This change would be non-breaking I believe. |
Stumbled into the same issue. It's usually "fixed" by avoiding eager compilations and using factories or something like that, but it is not possible in case of the |
@jnwng @migueloller any progress on this? |
@HosseinAgha, happy to push this to the finish line if the Apollo team so desires! 😄 |
@jnwng Apollo team please make this happen 🙏 |
When colocating fragments, circular dependencies often become an issue.
While GraphQL doesn't support circular fragment dependencies, it is
still possible to have circular dependencies in the component files that
declare the fragments.
An example of this is when rendering a tree structure using GraphQL.
While GraphQL doesn't allow for recursive queries, it is still possible
to query an array of descendants and build a tree data structure in the
client. This data structure can then be rendered recursively with React.
Pull Request Labels