Skip to content
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

Guidance on shared fragments #3284

Closed
jimisaacs opened this issue Nov 14, 2023 · 7 comments
Closed

Guidance on shared fragments #3284

jimisaacs opened this issue Nov 14, 2023 · 7 comments
Labels
question Issues that have a question which should be addressed

Comments

@jimisaacs
Copy link
Contributor

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:

  1. Copy the fragments between the 2 packages
  2. Put the shared fragments in the shared schema, though the 3rd package doesn't use them.
@jimisaacs jimisaacs added the question Issues that have a question which should be addressed label Nov 14, 2023
@jimisaacs
Copy link
Contributor Author

hmm, is there a 3rd option to have the fragments in their own target 🤔

@calvincestari
Copy link
Member

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.

@jimisaacs
Copy link
Contributor Author

@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.

@jimisaacs
Copy link
Contributor Author

jimisaacs commented Nov 29, 2023

What would you say to an option that could add import statements to generated operations, or event just certain sources?

@calvincestari
Copy link
Member

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.

@jimisaacs
Copy link
Contributor Author

jimisaacs commented Dec 1, 2023

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.

Copy link
Contributor

github-actions bot commented Mar 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that have a question which should be addressed
Projects
None yet
Development

No branches or pull requests

3 participants