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: Escape deprecation messages #2951

Merged
merged 12 commits into from Apr 12, 2023
Merged

Conversation

calvincestari
Copy link
Member

@calvincestari calvincestari commented Apr 11, 2023

Fixes #2879

  • Refactors deprecation message composition (#warning and @available) into one extension
  • Escapes all double quotes in deprecation reasons
  • Removes line feed processing and does not render multi-line deprecation warning/messages

@netlify
Copy link

netlify bot commented Apr 11, 2023

Deploy Preview for apollo-ios-docs canceled.

Name Link
🔨 Latest commit 5d78fe2
🔍 Latest deploy log https://app.netlify.com/sites/apollo-ios-docs/deploys/64370670bcb70f0008d92fd5

@calvincestari
Copy link
Member Author

@AnthonyMDev, working through this made me realize I don't think we're generating @available deprecation annotations for the new selection set initializers?

// These tests ensure that when given double quotes in SDL the generation of Swift code works as
// expected from frontend parsing all the way to rendering of attributes, comments andwarnings.
// There is a test here for all the places that the GraphQL schema supports the @deprecated
// directive.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding these tests. Super critical b/c if we change the back end to SwiftGraphQL someday we want to ensure it still works all the way through!

Copy link
Member Author

Choose a reason for hiding this comment

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

These tests don't include the characters \0 (null character), nor \' (single quote) because they're caught as syntax errors by graphql-js.

failed: caught error: "Syntax Error: Invalid character escape sequence: "\0".

failed: caught error: "Syntax Error: Invalid character escape sequence: "'".

I think this is because graphql-js is validating strings against the GraphQL spec definition of allowed escape characters. Those two characters are not in that list.

Copy link
Member Author

Choose a reason for hiding this comment

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

@AnthonyMDev similarly graphql-js does not allow \( either so there is no need to check and replace that character. What we spoke about yesterday.

failed: caught error: "Syntax Error: Invalid character escape sequence: "(".

@AnthonyMDev
Copy link
Contributor

@AnthonyMDev, working through this made me realize I don't think we're generating @available deprecation annotations for the new selection set initializers?

We definitely aren't, but I'm not sure if that's necessary. If the fields themselves have deprecation messages, you're just going to get duplicate warnings. What situation would you need to have a deprecation warning on the initializer itself?

@calvincestari
Copy link
Member Author

What situation would you need to have a deprecation warning on the initializer itself?

Consistency. The codegen configuration has an option to generate warnings on deprecation but we're making a decision to only implement them in some places; how should the user know where to expect them? I don't know if it's urgent we add them though.


forEach { character in
switch (character) {
case "\0": escapedString.append(#"\0"#)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm open to alternatives that would be more efficient or better performing than this; all the other ways I tried I couldn't use extended string delimiters and using regular string literals causes the escaped characters to be 'processed' instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like there has got to be a better way of doing this, but I'm not sure what that would be honestly, so lets go with it. This is not the most performance sensitive code to be honest.

I wonder if using a dictionary for the find and replaces would be slightly more performant, but if I remember correctly this switch statement should end up compiling into something very similar to that anyways. (I could be totally wrong about that, it's been a long time since I looked into that.)

@calvincestari calvincestari mentioned this pull request Apr 12, 2023
7 tasks
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.

Thanks for completing this very tedious fix!


forEach { character in
switch (character) {
case "\0": escapedString.append(#"\0"#)
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like there has got to be a better way of doing this, but I'm not sure what that would be honestly, so lets go with it. This is not the most performance sensitive code to be honest.

I wonder if using a dictionary for the find and replaces would be slightly more performant, but if I remember correctly this switch statement should end up compiling into something very similar to that anyways. (I could be totally wrong about that, it's been a long time since I looked into that.)

@calvincestari calvincestari merged commit 58f6d3f into main Apr 12, 2023
16 checks passed
@calvincestari calvincestari deleted the fix/escape-deprecation-messages branch April 12, 2023 19:37
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.

Deprecation messages are not escaped
2 participants