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

0.27.1: fields with undefined values present in args of generated types #434

Closed
shawnjones253 opened this issue Jan 10, 2024 · 8 comments
Closed
Labels
question Further information is requested

Comments

@shawnjones253
Copy link

shawnjones253 commented Jan 10, 2024

Describe the Bug
When using:

AND

  • you don't change the output folder for typegraphql-prisma generated types (you must have transpiled code to reproduce this, you can alternately use emitTranspiledCode = true to reproduce)

then Args() will have ALL keys present when deserialized, even those which the request didn't specify -- those which weren't specified in the request will be present with undefined values

Example:

link
args will be:

FindManyUserArgs {
  where: UserWhereInput {
    AND: undefined,
    OR: undefined,
    NOT: undefined,
    id: undefined,
    email: StringFilter {
      equals: '[email protected]',
      in: undefined,
      notIn: undefined,
      lt: undefined,
      lte: undefined,
      gt: undefined,
      gte: undefined,
      contains: undefined,
      startsWith: undefined,
      endsWith: undefined,
      not: undefined
    },
    name: undefined,
    posts: undefined
  },
  orderBy: undefined,
  cursor: undefined,
  take: undefined,
  skip: undefined,
  distinct: undefined
}

To Reproduce
git clone https://github.com/shawnjones253/typegraphql-prisma

git checkout issue-434-repro
cd typegraphql-prisma/examples/2-basic
npm install
npm run generate
npm run seed
npm run start

open localhost:4000 in web browser

send this gql query:

{ 
  usersCustom(
  	where: {
    	email: {equals: "[email protected]"}
  	}
	)
  { id }
}

Expected Behavior
args SHOULD be:

FindManyUserArgs {
  where: UserWhereInput { email: StringFilter { equals: '[email protected]' } }
}

this was the behavior with 0.27.0, you can verify this with
npm install -D -E [email protected]
and rerunning the repro above

Environment (please complete the following information):

  • OS: macOS 14.2
  • Node 20.4.0
  • typegraphql-prisma version 0.27.1
  • Prisma version 5.7.1
  • TypeScript version 4.9.4

Additional Context
I tried to workaround this by using emitGeneratedCode = false (this fixes it in the example repo) -- but in my actual project, I ran into tons of ReferenceError: Cannot access '....' before initialization despite using all the tsconfig options from here

@MichalLytek
Copy link
Owner

I don't see anything that could affect that:
image

What is your type-graphql version?

@MichalLytek MichalLytek added the question Further information is requested label Jan 10, 2024
@shawnjones253
Copy link
Author

shawnjones253 commented Jan 10, 2024

@MichalLytek here's the package.json with all the versions used in my repro

"type-graphql": "2.0.0-beta.4"

but i can also repro with 2.0.0-beta.3 and 2.0.0-beta.2

@shawnjones253
Copy link
Author

@MichalLytek it does seem the test snapshots were updated to expect all these undefined values in this commit

@MichalLytek
Copy link
Owner

but i can also repro with 2.0.0-beta.3 and 2.0.0-beta.2

So this is related to type-graphql core itself. Will check it.

@shawnjones253
Copy link
Author

shawnjones253 commented Jan 11, 2024

@MichalLytek i believe this may be due to changing the generator's target to es2022 here

i've been playing around locally, and changing that one line creates these two different class definitions in the emitted js:

es2019

let FindManyUserArgs = class FindManyUserArgs {
};

es2022

let FindManyUserArgs = class FindManyUserArgs {
    where;
    orderBy;
    cursor;
    take;
    skip;
    distinct;
};

If I understand correctly, before ES2022, classes had to define properties in the constructor, but since the generated classes in type-graphql don't have constructors, they don't get initialized just by creating an instance of the class (and therefore don't exist unless typegraphql core sets a value for them? guessing here)

@shawnjones253
Copy link
Author

@MichalLytek #435

@MichalLytek
Copy link
Owner

Closing as fixed by 4c053cc

@mmmeff
Copy link

mmmeff commented Feb 28, 2024

Thank you @MichalLytek ! Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants