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

Decorators cannot be used to decorate parameters. #899

Open
forabi-cosuno opened this issue Feb 15, 2023 · 1 comment
Open

Decorators cannot be used to decorate parameters. #899

forabi-cosuno opened this issue Feb 15, 2023 · 1 comment

Comments

@forabi-cosuno
Copy link

Trying to transform some TS that looks like this:

@Query((_returns) => AwardedBid)
  async awardedBidForAgent(@Ctx() context: ResolverContext, @Arg('id', (_type) => ID) id: string) {
    const { user } = context;

    const bid = await this.prisma.bid.findFirst({
	  /// ...
      rejectOnNotFound: true,
    });
    

    return {
		/// ....
    };
  }

Using this custom plugin:

function propIsRejectOnNotFound(prop) {
  return prop.key.name === 'rejectOnNotFound';
}

export default function (babel) {
  const { types: t } = babel;

  return {
    name: 'ast-transform', // not required
    visitor: {
      Identifier(path) {},
      CallExpression(path) {
        if (['findUnique', 'findFirst'].includes(path.node.callee.property.name)) {
          if (path.node.arguments[0].type === 'ObjectExpression') {
            console.log(path.node.arguments);
            const arg = path.node.arguments[0].properties.findIndex(propIsRejectOnNotFound);
            console.log({ arg });
            if (arg) {
              path.node.arguments[0].properties.splice(arg, 1);
              path.node.callee.property.name += 'OrThrow';
            }
          }
        }
      },
    },
  };
}

I get this error when using the CLI:

Decorators cannot be used to decorate parameters.
@eventualbuddha
Copy link
Collaborator

Try @codemod/[email protected] (just published) like so:

codemod --parser-plugins decorators-legacy …

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

2 participants