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

Using a query parameter named type generates invalid Rescript #30

Open
Kingdutch opened this issue May 19, 2022 · 2 comments · May be fixed by #91
Open

Using a query parameter named type generates invalid Rescript #30

Kingdutch opened this issue May 19, 2022 · 2 comments · May be fixed by #91
Labels
bug Something isn't working router Issue related to the router itself.
Milestone

Comments

@Kingdutch
Copy link
Collaborator

Syntax error!
  /<project>/src/routes/__generated__/RouteDeclarations.res:525:43-46

  523 ┆ prepared: prepared,
  524 ┆ 
  525 ┆   type: preparedProps.type,
  526 ┆   direction: preparedProps.direction,
  527 ┆   at: preparedProps.at,

  `type` is a reserved keyword. Keywords need to be escaped: \"type"
@Kingdutch Kingdutch added bug Something isn't working router Issue related to the router itself. labels May 19, 2022
@zth
Copy link
Owner

zth commented May 24, 2022

Good catch, we need to account for keywords.

@zth
Copy link
Owner

zth commented May 24, 2022

@Kingdutch if you're interested in getting your feet wet in the codegen, this one would probably be quite easy. There's a SafeParam module that's designed for preventing collisions between query params, path params, and built-ins like environment etc that we always use. I think solving this should be as easy as extending that variant to have RescriptKeyword({ realKey: string, collisionProtectedKey: string }) and just have collisionProtectedKey get a trailing underscore or similar.

Here's the code: https://github.com/zth/rescript-relay-router/blob/main/cli/RescriptRelayRouterCli__Codegen.res#L6-L42

@zth zth added this to the v1 beta milestone Jun 30, 2022
Kingdutch added a commit that referenced this issue Jul 19, 2022
The codegen tool did not yet account for reserved keywords when
generating code. This caused a query parameter such as `type` to
generate code that would refuse to compile.

To fix this a list of reserved keywords are added that get an underscore
added as suffix.

Fixes #30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working router Issue related to the router itself.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants