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

Subscript GraphQL variable from dictionary crash when Swift modifier used as key. #2759

Closed
SzymonMatysik opened this issue Jan 9, 2023 · 4 comments · Fixed by #2773
Closed
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation planned-next Slated to be included in the next release

Comments

@SzymonMatysik
Copy link

SzymonMatysik commented Jan 9, 2023

Summary

Hey there, great thanks for hard work put into new release!

Recently I've started to migrate from 0.53 to 1.0.5 and have to say - it's not a very easy task to achieve. Now I've stomped on issue that nobody else mentioned before (based on my research).

Everything was working fine before the migration - I think it's issue related to the codegen feature.
When I got in schema variable in fragment named after Swift's special words default, public, private or else then in generated code it's __data["'public'"] } (apostrophes on each side to escape the special word)
It leads to a problem in getting the value resulting a crash as in subscript.
part of generated file:

    public var `public`: GraphQLNullable<Bool> {
      get { __data["`public`"] }
      set { __data["`public`"] = newValue }
    }

Maybe we should stripe the apostrophes which are clearly from the Swift requirements not from a schema.

Version

1.0.5

Steps to reproduce the behavior

  • Make schema with variable in any model named after Swift's special word for example public: Bool.
  • Generate schema.
  • Check string representation of variable in Swift generated file.

Logs

Could not cast value of type 'Swift.Optional<ApolloAPI.GraphQLOperationVariableValue>' (0x15460b190) to 'ApolloAPI.GraphQLNullable<Swift.Bool>' (0x1510a3608).
(lldb) 

Anything else?

As a workaround I've applied direct dictionary lookup for public field as follows:
let lhsPublic: GraphQLNullable<Bool> = lhs.__data["public"]

@SzymonMatysik SzymonMatysik added bug Generally incorrect behavior needs investigation labels Jan 9, 2023
@calvincestari
Copy link
Member

Thanks for the bug report @SzymonMatysik. We'll get this fixed in a patch release; we're planning on releasing 1.0.6 today and 1.0.7 by the end of the week. It'll be in one of those.

@calvincestari calvincestari added codegen Issues related to or arising from code generation and removed needs investigation labels Jan 9, 2023
@calvincestari calvincestari added this to the Patch Releases (1.0.x) milestone Jan 9, 2023
@calvincestari
Copy link
Member

Note that this bug is only apparent on input types, selection sets do not have this issue.

@calvincestari calvincestari added the planned-next Slated to be included in the next release label Jan 11, 2023
@calvincestari calvincestari self-assigned this Jan 11, 2023
@calvincestari
Copy link
Member

Adding this to "planned-next" because fixing #2753 will need this to be fixed too before it's all functional.

@calvincestari
Copy link
Member

@SzymonMatysik this is fixed, available on main, and will go out in the next patch release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation planned-next Slated to be included in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants