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

Enable operations-only code generation #2526

Closed
derrh opened this issue Sep 28, 2022 · 5 comments
Closed

Enable operations-only code generation #2526

derrh opened this issue Sep 28, 2022 · 5 comments
Labels
codegen Issues related to or arising from code generation

Comments

@derrh
Copy link

derrh commented Sep 28, 2022

Feature request

One goal I've been exploring for a large project is the ability to generate a Schema Types module and Operations modules independently and is separate repos.

Motivation

I'd like to allow feature modules to perform codegen for their own operations, but depend on a pre-existing, schema-types module. As a feature module owner, I could maintain my own repo/SPM module that depends on a remote schema-types repo. My feature module could provide it's own codegen config but not regenerate the schema types files.

Proposed solution

Make the schemaTypes field optional on FileOutputs or provide a none case in SchemaTypesFileOutput.ModuleType. In either case, if .none is requested, the schema types files are not codegen'd. Generated operations files would import schema types from the module identified by SchemaName.

Outstanding Questions

Perhaps this is a workflow you've already considered and there is a solution in place?

1.0 is looking great! Thanks!

@calvincestari
Copy link
Member

Hi @derrh 👋🏻 - thanks for the feature request.

I think you might be able to already achieve the separate repos with the current config by simply using the correct paths, which would lead to separate repo locations. I haven't tried it so I cannot say for certain but I believe the operation file import statements will still work as expected because a separate schema module is already an option in FileOutput. SchemaTypesFileOutput. ModuleType. It is not currently possible to only generate operation files though.

A detail you may not be aware of is that parsing the schema and operations would still be required even if you only wanted the operation files to be generated. This is because of the AST that is produced during that parsing and is used by the operation templates to generate those files will full knowledge of all the available schema types. So the only step you'd be 'skipping' is writing the schema files, which seems quite inefficient.

If the AST were able to be persisted externally and then referenced during operation file creation I could see a path to this working. Honestly though I don't think this is something we will end up implementing and supporting ourselves. You are always able to fork the repo, implement the feature, and then contribute it back if you feel it's of value to the wider community.

@calvincestari calvincestari added the codegen Issues related to or arising from code generation label Sep 29, 2022
@derrh
Copy link
Author

derrh commented Dec 8, 2022

Circling back to this. I can see how this might not be an advisable approach. Another realization I've had is that the generated schema types are a subset of the total graph's types depending on the operations, which means that in many cases updating the changes for a feature package's operations would result in changes to the schema package's types as well. Still exploring options, but leaning more toward a monorepo with separate packages.

@calvincestari
Copy link
Member

Another realization I've had is that the generated schema types are a subset of the total graph's types depending on the operations, which means that in many cases updating the changes for a feature package's operations would result in changes to the schema package's types as well.

Yes, this is correct. Rather than generate every type in the schema, only the referenced types are generated into the schema types module. When you consider large schemas such as the GitHub schema it makes sense why.

@AnthonyMDev
Copy link
Contributor

We're going to track this in #3165. Closing this as duplicate

@AnthonyMDev AnthonyMDev closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
Copy link

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
codegen Issues related to or arising from code generation
Projects
None yet
Development

No branches or pull requests

3 participants