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

Next.js reflection fails to destructure @Arg() decorator InputType variables #722

Closed
redbaron76 opened this issue Oct 12, 2020 · 1 comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists

Comments

@redbaron76
Copy link

Describe the Bug
I don't understand if it's an issue related to TypeGraphQL or it involves some Babel plugins used to transpile my Next.js application. But when I use @Arg("input") { var1, var2 }: MyInputType as a single parameter in a @Mutation() method in a @Resolver() class and I try to inline destructure my Input type, TypeGraphQL reflection seems to crash with Cannot read property '0' of undefined.

To Reproduce
This is my method that generates the error (and my workaround to fix it):

@Resolver((of) => User)
export class UserResolver {
  
  .....

  @Mutation((returns) => User)
  async register(
    // @Arg("input") { firstName, lastName, email, password }: RegisterInput ---> ERROR!!!
    @Arg("input") registerInput: RegisterInput ---> IT WORKS
  ): Promise<User> {
    const { firstName, lastName, email, password } = registerInput;
    const hashedPassword = await bcrypt.hash(password, 12);

    const user = await User.create({
      firstName,
      lastName,
      email,
      password: hashedPassword,
    }).save();

    return user;
  }
}

.babelrc file in my Next.js project root

{
  "presets": ["next/babel"],
  "plugins": [
    "babel-plugin-transform-typescript-metadata",
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
    "babel-plugin-parameter-decorator"
  ]
}

Expected Behavior
It should work as expected also destructuring variables from the incoming input type.

Environment

  • OS: OSX 10.15.7 Catalina
  • Node 10.22.0
  • Package version 1.0.0
  • TypeScript version 4.0.3

Additional Context

  • Next.js 9.5.4
  • TypeORM 0.2.28
  • Postgres
@MichalLytek
Copy link
Owner

It's related to the babel plugin as it looks like the reflection plugin couldn't handle the destructuring syntax.

All the babel and JS discussion in happening in #55, so closing this one as duplicate 🔒

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists labels Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Duplicate 🔑 This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants