Skip to content

Skip redundant modifiers#1241

Merged
trevor-scheer merged 1 commit intoapollographql:masterfrom
michaelnisi:1177
Jul 23, 2019
Merged

Skip redundant modifiers#1241
trevor-scheer merged 1 commit intoapollographql:masterfrom
michaelnisi:1177

Conversation

@michaelnisi
Copy link
Copy Markdown
Contributor

@michaelnisi michaelnisi commented May 7, 2019

Resolves #1177. The goal is to prevent compiler warnings for redundant access-level modifiers when using --namespace.

It covers queries and fragments, according to basic testing at least, resolving the initial issue. Are there more types affected by this? @martijnwalraven

  • Update CHANGELOG.md* with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass

@trevor-scheer
Copy link
Copy Markdown
Contributor

Thanks for taking the time to put this together @michaelnisi! The PR is greatly appreciated. I'm going to hand this off to @designatednerd for review since she's our new mobile architect 😄

@trevor-scheer trevor-scheer requested review from designatednerd and removed request for jbaxleyiii and trevor-scheer July 12, 2019 18:25
@trevor-scheer trevor-scheer added 🐦 component - swift 🤖 component - codegen related to the codegen core packages labels Jul 12, 2019
Copy link
Copy Markdown
Contributor

@designatednerd designatednerd left a comment

Choose a reason for hiding this comment

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

I'm crap at typescript so I'll have to defer to an actual ts developer on that bit.

);

expect(generator.output).toBe(stripIndent`
struct Hero: GraphQLFragment {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't been able to dig super-deep into what's happening here, but is the adoptedProtocols thing what shoves this into an extension rather than just into the big namespaced enum?

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.

Give me a minute to refresh my memory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@michaelnisi Any recollection?

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.

First thing tomorrow morning.

Copy link
Copy Markdown
Contributor Author

@michaelnisi michaelnisi Jul 16, 2019

Choose a reason for hiding this comment

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

No, these changes simply skip the public modifier if we are in a namespace, see below. 👇 adoptedProtocols is checked to see if our struct is a fragment.

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.

@designatednerd Lost interest? 🙂

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nope lost the changes in my flood of email 😄 will take another look

@michaelnisi
Copy link
Copy Markdown
Contributor Author

michaelnisi commented Jul 16, 2019

Rebased and reviewed. These changes simply make the previously static public and final modifiers dynamic to prevent redundancy warnings #1177.

The goal is to skip the public modifier in the namespaced case. It boils down to this 👇

For classes:

const isRedundant = !!namespace;
const modifiers = isRedundant ? ["final"] : ["public", "final"];

For structs:

const isRedundant = adoptedProtocols.includes("GraphQLFragment") && !!namespace;
const modifier = isRedundant ? "" : "public ";

These changes cover queries and fragments.

@designatednerd
Copy link
Copy Markdown
Contributor

@trevor-scheer I'll leave this to you to review the typescript on Monday but the swift stuff is ready to ship!

Copy link
Copy Markdown
Contributor

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

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

Minor nitpick but TS changes LGTM!

Comment thread packages/apollo-codegen-swift/src/codeGeneration.ts Outdated
@michaelnisi
Copy link
Copy Markdown
Contributor Author

Rebased and ready to go.

However, there’s a new (unrelated?) failing CI check for Node.js 10:

Summary of all failing tests
 FAIL  packages/apollo/src/commands/client/__tests__/generate.test.ts (6.301s)
  ● client:codegen › extracts queries with a custom tagName provided in the config

    TypeError [ERR_INVALID_ARG_TYPE]: The "warning" argument must be one of type Error or string. Received type object

Let me know if this is a new requirement the Swift generator is neglecting and if I can help.

@trevor-scheer trevor-scheer merged commit 9a0ab3a into apollographql:master Jul 23, 2019
@trevor-scheer
Copy link
Copy Markdown
Contributor

@michaelnisi those are some flaky tests that we've been tolerating for quite some time now. All was well after a re-run. Thanks for the contribution! 🎉

@gsabran
Copy link
Copy Markdown

gsabran commented Jul 30, 2019

This should only apply if the classes and structs are defined within an extension, which I think is equivalent to outputIndividualFiles == true. Else the code generated now looks like

public enum MyNameSpace {
    struct Hero: GraphQLFragment {
        public var name: String
        public var age: Int
    }
}

and the struct is internal.

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.

[Swift] Xcode 10.2 and use of namespace causes compiler warnings.

4 participants