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

feat: Add support for .none module type - Part 1: File Templates #2229

Merged
merged 24 commits into from
Apr 5, 2022

Conversation

calvincestari
Copy link
Member

@calvincestari calvincestari commented Mar 29, 2022

PR 1 for #2034 - This refactor grew larger than I anticipated so I'm trying to limit the changesets and keep the PRs focused; this PR refactors the file templates to support .none module type.

  • Supporting the .none module type by wrapping the template in a namespace seemed simple enough until I got to having to split the header and import statements from the rest of the template body; that was complicated by each template handling the header/import statement additions.
  • Individual templates have now been pared back to focus on their single responsibility and conform to TemplateRenderer.
  • TemplateRenderer is a protocol that is responsible for combining individual templates based on the target of the template and the codegen configuration. Each individual template conforming to the protocol provides the base properties and the extension handles rendering and combining templates as needed.
  • Also introduced is a reference wrapper for value types; ReferenceWrapped. This allows us to pass around the codegen configuration struct internally without copying it each time it's passed to a new function.
  • The individual template tests don't validate header/import statements anymore since they don't pull them in.
  • There is a bit of duplication between the TemplateRenderer and ImportStatementTemplate tests for checking the import scenarios.

Note: This PR will not pass CI checks until Part 2 is merged into it.

@netlify
Copy link

netlify bot commented Mar 29, 2022

Deploy Preview for apollo-ios-docs ready!

Name Link
🔨 Latest commit 516e911
🔍 Latest deploy log https://app.netlify.com/sites/apollo-ios-docs/deploys/624cb4a4b0403700099347f8
😎 Deploy Preview https://deploy-preview-2229--apollo-ios-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@AnthonyMDev AnthonyMDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! We should talk about what to do about shared Fragments, but otherwise this is good to go!


func render() -> String {
var target: TemplateTarget { .operationFile }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a fragment is being shared across operations and those operations are in separate modules, the Fragment would need to be include in the schema module. We probably need to put some more thought into this.

calvincestari and others added 3 commits April 5, 2022 14:01
…2234)

* Adapt EnumFileGenerator to FileGenerator
* Adapt ObjectFileGenerator to FileGenerator
* Adapt InterfaceFileGenerator to FileGenerator
* Adapt FragmentFileGenerator to FileGenerator
* Adapt InputObjectFileGenerator to FileGenerator
* Adapt OperationFileGenerator to FileGenerator
* Adapt SchemaFileGenerator to FileGenerator
* Adapt UnionFileGenerator to FileGenerator
* Add Equatable conformance to OperationDefinition
* Remove render function from TemplateRenderer protocol - only in extension
* Rename MockTemplate to MockFileTemplate
* Add FileGenerator protocol
* Move path resolver logic into FileGenerator
* Add FileGenerator tests
* Update SchemaModuleFileGenerator for ReferenceWrapped
* Adapt ApolloCodegen to ReferenceWrapped and FileGenerator
* fix: Test should match all rendered content
* fix: remove equality implementation, will be synthesized instead
@calvincestari calvincestari force-pushed the 1.0/moduletype-none-filetemplates branch from 1607ece to 516e911 Compare April 5, 2022 21:02
@calvincestari calvincestari merged commit 36c30cf into release/1.0 Apr 5, 2022
@calvincestari calvincestari deleted the 1.0/moduletype-none-filetemplates branch April 5, 2022 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants