Skip to content

Decorators cannot be used to decorate parameters. #899

@forabi-cosuno

Description

@forabi-cosuno

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions