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

codegen doesn't protect against typenames which are typescript keywords #4887

Open
4 tasks
cmcconomyfwig opened this issue Dec 2, 2022 · 1 comment
Open
4 tasks

Comments

@cmcconomyfwig
Copy link

cmcconomyfwig commented Dec 2, 2022

Issue workflow progress

Progress of the issue based on the Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

When generating a OData endpoint, I ran into an issue that one of the entities was called import.
This conflicts with an existing typescript keyword, and so the code caused errors.

an example snippet from the types.ts file:

  owner_imports?: Maybe<Array<Maybe<import>>>;
  owner_importsById?: Maybe<import>;

To Reproduce
Steps to reproduce the behavior:

(Can't give you access to this OData source)

Expected behavior

Code works as expected.
In order to avoid namespace collision, perhaps the mesh build step can create types with the name t__<name> instead?

Environment:

  • OS: MacOS
  • "@graphql-mesh/cli": "^0.80.4",
  • "@graphql-mesh/odata": "^0.20.35",
  • NodeJS: v16.14.0
@cmcconomyfwig
Copy link
Author

I tried setting

codegen:
  skipTypename: false
  namingConvention: './gql-mesh-namingfn'

with the js adding _obj to any incoming string with the value in

const reserved_js_words = ['abstract',	'arguments',	'await',	'boolean',
    'break',	'byte',	'case',	'catch',
    'char',	'class',	'const',	'continue',
    'debugger',	'default',	'delete',	'do',
    'double',	'else',	'enum',	'eval',
    'export',	'extends',	'false',	'final',
    'finally',	'float',	'for',	'function',
    'goto',	'if',	'implements',	'import',
    'in',	'instanceof',	'int',	'interface',
    'let',	'long',	'native',	'new',
    'null',	'package',	'private',	'protected',
    'public',	'return',	'short',	'static',
    'super',	'switch',	'synchronized',	'this',
    'throw',	'throws',	'transient',	'true',
    'try',	'typeof',	'var',	'void',
    'volatile',	'while',	'with',	'yield']

But this appeared to have zero effect. (I verified with some console.out()'s that the code was being invoked, and it was)

This was referenced Apr 30, 2024
This was referenced May 7, 2024
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

No branches or pull requests

1 participant