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: fields with undefined values present in args of generated types #435

Closed

Conversation

shawnjones253
Copy link

fix for: #434

This restores the previous behavior of input keys only being set when specified by the api request via variables.

Unfortunately, this only guarantees a fix when emitTranspiledCode = true is used (the default). However, if output = 'someDirOutsideOfNodeModules' is used WITHOUT emitTranspiledCode = true, then the consuming app must do one of:

  • target <= es2021
  • specify "useDefineForClassFields": false if target == es2022

UseDefineForClassFields
Default: true if [target](https://www.typescriptlang.org/tsconfig#target) is ES2022 or higher, including ESNext; false otherwise.

useDefineForClassFields true false
ES2022 TS Playground TS Playground
<= ES2021 TS Playground TS Playground

some interesting reading that pointed me in this direction:
swc-project/swc#7055
microsoft/TypeScript#45995

@shawnjones253
Copy link
Author

shawnjones253 commented Jan 14, 2024

if the intent is to not have undefined values at runtime for unspecified request keys, should useDefineForClassFields: false be added to the required tsconfig.json options here? (it is only needed when emitTranspiledCode = false)

@shawnjones253
Copy link
Author

@MichalLytek -- are you open to this PR? our team reverted to 0.27.0 due to the above but we're really missing the speed boost that came with 0.27.1 :)

@MichalLytek
Copy link
Owner

I found this to be a workaround. I need to play with es2022 in typegraphql core itself I've recently merged there a fix to get rid of undefined values from transformed inputs.

@shawnjones253
Copy link
Author

@MichalLytek any updates on this issue?

@MichalLytek
Copy link
Owner

@shawnjones253
Setting target to es2022 makes this tests failing:

Summary of all failing tests
 FAIL  tests/functional/resolvers.ts
  ● Resolvers › Functional › shouldn't create properties of nullable args

    expect(received).not.toHaveProperty(path)

    Expected path: not "optionalField"

    Received value: undefined

      1818 |       expect(mutationResult.errors).toBeUndefined();
      1819 |
    > 1820 |       const result = mutationResult.data!.mutationWithTripleNestedInputs;
           |                                            ^
      1821 |       expect(result).toEqual(30);
      1822 |
      1823 |       expect(mutationInputValue).toBeInstanceOf(classes.SampleTripleNestedInput);

      at Object.<anonymous> (tests/functional/resolvers.ts:1820:44)

  ● Resolvers › Functional › should create instances of nested input fields input objects without undefined

    expect(received).not.toHaveProperty(path)

    Expected path: not "optionalNestedField"

    Received value: undefined

      1847 |     it("should create instance of root object when root type is provided", async () => {
      1848 |       const query = `query {
    > 1849 |         sampleQuery {
           |                                ^
      1850 |           fieldResolverWithRoot
      1851 |           getterField
      1852 |         }

      at Object.<anonymous> (tests/functional/resolvers.ts:1849:44)

I think I will just downgrade target in prisma generator to make it matching with type-graphql core.

@MichalLytek
Copy link
Owner

Closing as superseded by 4c053cc 🔒

@MichalLytek MichalLytek closed this Feb 7, 2024
@shawnjones253
Copy link
Author

@MichalLytek now could I just bug you for a new release 😅

@shawnjones253
Copy link
Author

@MichalLytek sorry to nag -- making another plea for a release -- our team is eager to get back to the fast version as it saves us hundreds of seconds when generating typegraphql types

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.

2 participants