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

fix: swift file names #713

Merged
merged 4 commits into from
Sep 25, 2023
Merged

fix: swift file names #713

merged 4 commits into from
Sep 25, 2023

Conversation

dpilch
Copy link
Member

@dpilch dpilch commented Sep 25, 2023

Description of changes

Type generation for Swift is always generating multiple files. Additionally the when generating multiple files the filename generated is incorrect.

Fallback to old type generation if generating to multiple files. When using the GraphQL generator directly the filenames will still be incorrect.

Issue #, if available

#711

Description of how you validated changes

  • unit testing
  • Manual testing

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

if (outputs.length === 1) {
const [[, contents]] = outputs;
fs.outputFileSync(path.resolve(outputPath), contents);
if (target === 'swift' && fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@dpilch dpilch marked this pull request as ready for review September 25, 2023 17:02
@dpilch dpilch requested a review from a team as a code owner September 25, 2023 17:02
@dpilch dpilch mentioned this pull request Sep 25, 2023
3 tasks
queries,
target,
introspection,
multipleSwiftFiles: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this flag still needed for the current PR? Looks like the change of consuming this value is not included

Copy link
Member Author

Choose a reason for hiding this comment

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

This is necessary to ensure that multiple Swift files are not used in the graphql-generator package.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is currently defaulted to true.

const { schema, target, queries, multipleSwiftFiles = true, introspection = false } = options;

generate(queryFilePaths, schemaPath, outputPath, '', target, '', {
addTypename: true,
complexObjectSupport: 'auto',
});
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't the new generateTypesHelper handle multiple swift file generation yet?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is bugged. The generateTypesHelper does not set the correct filenames for the generated types. It will require a more complex fix. This solution will fix current production.

Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

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

Verified locally by amplify-dev codegen. The multiple files are generated when the generatedFileName is configured as a folder name which already exists. Otherwise it generates single file.
TODO for later PR: a e2e test to cover the single/multiple file generation for swift

@dpilch dpilch merged commit a901362 into main Sep 25, 2023
3 checks passed
@dpilch dpilch deleted the fix-swift-file-names branch September 25, 2023 18:17
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.

3 participants