filipstefansson / nexus-validate

🔑 Add argument validation to your GraphQL Nexus API.
35 stars 8 forks source link

Yup transformers don't transform args #10

Closed ben-walker closed 3 years ago

ben-walker commented 3 years ago

First off, thanks for building this, it's great! Just what I wanted from a Nexus validation package!

Sorry if this is a known limitation, but I noticed that yup transformers don't seem to impact what gets passed to the resolve function. For instance, in this code:

t.field("userSignUp", {
      type: UserAuthPayload,
      args: {
        email: nonNull(stringArg()),
        username: nonNull(stringArg()),
        password: nonNull(stringArg()),
      },
      validate: ({ string }) => ({
        email: string().email(),
        username: string().min(3).max(20).trim(),
        password: string().min(8),
      }),
      resolve: async (_root, { email, username, password }, ctx) => {
        ...
        const user = await ctx.prisma.user.create({
          data: { discriminator, email, passwordHash, username },
        });
        ...
        return { user };
      },

The username field can still contain leading/trailing spaces, even with the call to trim() in the validate function.

filipstefansson commented 3 years ago

@ben-walker Sorry for the late response, I totally missed this issue!

I understand the problem here... Let me take a look and get back to you! It would be a nice feature if we could apply the transforms before passing them to the resolver.

filipstefansson commented 3 years ago

@ben-walker this was added in #11 that was just merged! Credit to @paolotiu.

ben-walker commented 3 years ago

Awesome, you love to see it!