Skip to content

Swift: Fix regression for individual files. #1451

Merged
designatednerd merged 7 commits intomasterfrom
ellen/fix-regression
Aug 2, 2019
Merged

Swift: Fix regression for individual files. #1451
designatednerd merged 7 commits intomasterfrom
ellen/fix-regression

Conversation

@designatednerd
Copy link
Copy Markdown
Contributor

#1449 Pointed out that #1241 introduced a regression when files are being output individually. This PR updates our logic to make sure that information is shared and then fix the issue.

@designatednerd designatednerd added 🐦 component - swift 🤖 component - codegen related to the codegen core packages labels Jul 30, 2019
@gsabran
Copy link
Copy Markdown

gsabran commented Jul 30, 2019

Thanks for making this PR so promptly!
Do you also need to change isRedundant here

to const isRedundant = outputIndividualFiles && !!namespace;?

@designatednerd
Copy link
Copy Markdown
Contributor Author

@gsabran Guh, good catch - there were a couple things that seem to have not made the bus on my last commit.

@designatednerd
Copy link
Copy Markdown
Contributor Author

I'm gonna take another look at this in the morning before merging - @JacksonKearl let me know if any of the TS looks fishy to you

fragments
} = this.context;
const isRedundant = !!namespace;
const isRedundant = !!namespace && !outputIndividualFiles;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Isn't the codegen written with extensions when outputIndividualFiles is true? In that case this should be

const isRedundant = !!namespace && outputIndividualFiles;

right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're correct that it's written with extensions when outputIndividualFiles is true, but isRedundant should only ever be true if we're not outputting individual files.

If isRedundant is true, codegen omits the public, which is the behavior filed as a bug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After figuring out the thing I fucked up, yep, you're right!

adoptedProtocols.includes("GraphQLFragment") && !!namespace;
adoptedProtocols.includes("GraphQLFragment") &&
!!namespace &&
!outputIndividualFiles;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same question regarding whether !outputIndividualFiles should be outputIndividualFiles

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

same answer

@designatednerd
Copy link
Copy Markdown
Contributor Author

@gsabran I'll wait on your 👍to merge this one - let me know if you have more questions!

@gsabran
Copy link
Copy Markdown

gsabran commented Jul 31, 2019

public is redundant for extensions so the desired outputs are

public enum MyNameSpace {}

public extension MyNameSpace {
   struct Hero: GraphQLFragment { // <- public would be redundant here
        public var name: String
        public var age: Int
    }
}

but not for enums as

public enum MyNameSpace {
    public struct Hero: GraphQLFragment { // <- public is required here
        public var name: String
        public var age: Int
    }
}

so I think we should only look for redundancy when the codegen generates extensions, ie when it outputs multiple files. Maybe I'm misunderstanding what outputIndividualFiles stands for.

@designatednerd
Copy link
Copy Markdown
Contributor Author

designatednerd commented Aug 1, 2019

AHA. I think I see where I missed something - the JS !! operator works different than I thought it did. Good catch!

@designatednerd
Copy link
Copy Markdown
Contributor Author

@gsabran better?

Copy link
Copy Markdown

@JacksonKearl JacksonKearl left a comment

Choose a reason for hiding this comment

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

Seems reasonable on the TS side, only thing I might add is more documentation around what the parameter is doing, perhaps in the form of some docstrings. As is, I think it could be difficult for someone adding a new feature in the future who need to use one of these functions to know if they should be passing true or false for that parameter.

classDeclarationForOperation(operation: Operation) {
classDeclarationForOperation(
operation: Operation,
outputIndividualFiles: boolean
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'd add a docstring to describe what exactly this parameter is doing (maybe with examples of the difference in output?), because it's not very clear to me just looking at it.

variant: Variant;
typeCase?: TypeCase;
},
outputIndividualFiles: boolean,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same here re docstring

@designatednerd designatednerd mentioned this pull request Aug 1, 2019
4 tasks
@designatednerd
Copy link
Copy Markdown
Contributor Author

@gsabran @JacksonKearl Would love 👍s from you guys if you think this is ready to go - would love to get this merged soon so we can put it out with a patch release

@designatednerd designatednerd merged commit 5125f5d into master Aug 2, 2019
@designatednerd designatednerd deleted the ellen/fix-regression branch August 3, 2019 14:36
@gsabran
Copy link
Copy Markdown

gsabran commented Aug 4, 2019

thanks for making this change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐦 component - swift 🤖 component - codegen related to the codegen core packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants