-
Notifications
You must be signed in to change notification settings - Fork 722
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
Code generation incorrect for field 'self' #193
Comments
Hi @kballard I've tried to reproduce this issue with the latest version of Apollo-Codegen (apollographql/apollo-tooling@7723fcd). I updated an existing test to have a property declaration with the name of 'self' and the generator correctly escaped it. The Test File was found here:
I also verified that both 'self', and 'Self' are in the reserved keywords list defined here: https://github.com/apollographql/apollo-codegen/blob/master/src/swift/language.ts#L35-L53 Can you confirm if this is still an issue and better steps to reproduce? |
@lilyball Is this issue still occurring? The reserved keywords list has moved to here: https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-codegen-swift/src/language.ts#L41 and it does still contain both |
Yes it's still occurring. I just added a public var `self`: Self? { and the usage of the unescaped |
Innnnteresting. I'll have a look! Thanks for confirming. |
@lilyball OK finally gathering the courage to dive into typescript and deal with this. So I can understand better what's happening here, is |
No, but |
Which is to say, if I use |
OK - that will help me at least come up with some kind of test for it, at least. Thank you! |
Fix shipped with |
I finally got around to testing this and public var `self`: Self? {
…
} I think the problem is the type is |
Ergh, I agree - I'm going to add a task for this to the iOS Swift Codegen project so I don't forget about it. @lilyball If you're interested in making a fix on the TypeScript stuff in the meantime, we'd love to see a PR on the tooling repo |
The source generator now operates using a string wrapper type called `SwiftSource`. Identifiers are escaped when converting into `SwiftSource` values, with an alternative method for producing escaped string literals. An escape hatch is provided for disabling escapes, but the default behavior is to escape all identifiers in the dynamic input. Most `SwiftSource` values are produced by a tagged template literal, which allows for easy mixing of string literals containing Swift keywords and dynamic input that needs escaping. As part of this, rewrite string escaping such that it actually escapes string contents properly. This required fixing a test that had a bad spec enforcing broken behavior. Fixes apollographql/apollo-ios#193. Fixes apollographql/apollo-ios#752.
The source generator now operates using a string wrapper type called `SwiftSource`. Identifiers are escaped when converting into `SwiftSource` values, with an alternative method for producing escaped string literals. An escape hatch is provided for disabling escapes, but the default behavior is to escape all identifiers in the dynamic input. Most `SwiftSource` values are produced by a tagged template literal, which allows for easy mixing of string literals containing Swift keywords and dynamic input that needs escaping. As part of this, rewrite string escaping such that it actually escapes string contents properly. This required fixing a test that had a bad spec enforcing broken behavior. Fixes apollographql/apollo-ios#193. Fixes apollographql/apollo-ios#752.
The source generator now operates using a string wrapper type called `SwiftSource`. Identifiers are escaped when converting into `SwiftSource` values, with an alternative method for producing escaped string literals. An escape hatch is provided for disabling escapes, but the default behavior is to escape all identifiers in the dynamic input. Most `SwiftSource` values are produced by a tagged template literal, which allows for easy mixing of string literals containing Swift keywords and dynamic input that needs escaping. As part of this, rewrite string escaping such that it actually escapes string contents properly. This required fixing a test that had a bad spec enforcing broken behavior. Fixes apollographql/apollo-ios#193. Fixes apollographql/apollo-ios#752.
The source generator now operates using a string wrapper type called `SwiftSource`. Identifiers are escaped when converting into `SwiftSource` values, with an alternative method for producing escaped string literals. An escape hatch is provided for disabling escapes, but the default behavior is to escape all identifiers in the dynamic input. Most `SwiftSource` values are produced by a tagged template literal, which allows for easy mixing of string literals containing Swift keywords and dynamic input that needs escaping. As part of this, rewrite string escaping such that it actually escapes string contents properly. This required fixing a test that had a bad spec enforcing broken behavior. Fixes apollographql/apollo-ios#193. Fixes apollographql/apollo-ios#752.
The source generator now operates using a string wrapper type called `SwiftSource`. Identifiers are escaped when converting into `SwiftSource` values, with an alternative method for producing escaped string literals. An escape hatch is provided for disabling escapes, but the default behavior is to escape all identifiers in the dynamic input. Most `SwiftSource` values are produced by a tagged template literal, which allows for easy mixing of string literals containing Swift keywords and dynamic input that needs escaping. As part of this, rewrite string escaping such that it actually escapes string contents properly. This required fixing a test that had a bad spec enforcing broken behavior. This commit makes the test added earlier pass. Fixes apollographql/apollo-ios#193. Fixes apollographql/apollo-ios#752.
If I have a field named
self
in a GraphQL query, the code generator produces code that referencesSelf.selections
, which is invalid asSelf
is a keyword and so the code fails to compile. The current workaround is to alias the field to a different name, though unfortunately the nameself_
doesn't work as Apollo still produces the type nameSelf
.The code generator should recognize keywords and work around them somehow, either by judicious insertion of backticks in the generated code, or by renaming the type.
The text was updated successfully, but these errors were encountered: