apollo-ios
apollo-ios copied to clipboard
Guidance on shared fragments
Question
Hello, we're looking for some guidance on how to achieve shared fragments.
Taking this as an example, there's 3 packages that all contain operations. They use the same shared schema package, but 2 of the 3 packages want to share fragments.
Currently I only know 2 options:
- Copy the fragments between the 2 packages
- Put the shared fragments in the shared schema, though the 3rd package doesn't use them.
hmm, is there a 3rd option to have the fragments in their own target 🤔
Hey Jim, sorry we missed this earlier.
I haven't tried this myself yet but I wonder if you could use the relative value for output.operations in the config. Place that file in a location that is it's own package and the other 2 packages would then have to manually import the fragment package.
@calvincestari we actually do use relative in our setup, but giving this some more thought, the problem isn't the package setup, it's the generated operations sources. To have the shared fragments in another package means the generated operations that use them would need import MySharedFragments automatically added to them. Without that, there is only 2 options, either 1, generate the fragments for all operations that use them, or 2, generate them in the shared schema lib, even though there could be dependents of the shared schema lib that do not use the included shared fragments.
What would you say to an option that could add import statements to generated operations, or event just certain sources?
Without that, there is only 2 options, either 1, generate the fragments for all operations that use them, or 2, generate them in the shared schema lib, even though there could be dependents of the shared schema lib that do not use the included shared fragments.
My preference would be option 2 in this case.
What would you say to an option that could add import statements to generated operations, or event just certain sources?
What does that config end up looking like is the question.
What does that config end up looking like is the question.
Myself and a colleague of mine have been working on this, and may open a PR soon.
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.