title: GraphQL rate limit on mutations
body: <p>I am trying to implement a rate limit on GraphQL <strong>Mutation</strong> when creating new users. I successfully implemented it in Queries but could not do the same on Mutations, any advice or resource on how I can solve this would be much appreciated.</p>
  <p>Thanks in advance.</p>
  <ul>
  <li>imports in resolvers/users</li>
  </ul>
  <pre><code>const bcrypt = require('bcrypt');
  const { UserInputError } = require('apollo-server');
  const { getGraphQLRateLimiter } = require('graphql-rate-limit')
  
  const { validateCreateInput } = require('../../util/validators');
  const User = require('../../models/User');
  </code></pre>
  <ul>
  <li>rate limiter declaration</li>
  </ul>
  <pre><code>const rateLimiter = getGraphQLRateLimiter({ identifyContext: (ctx) =&gt; ctx.id });
  </code></pre>
  <ul>
  <li>Query with rate limitation which works fine</li>
  </ul>
  <pre><code>Query: {
          getUsers: async (parent, args, context, info) =&gt; {
              try {
                  const errorMessage = await rateLimiter(
                      { parent, args, context, info },
                      { max: 1, window: '3s' }
                  );
                  if (errorMessage) throw new Error(errorMessage);
                  const users = await User.find().sort({ createdAt: -1 });
                  return users;
              } catch (err) {
                  throw new Error(err);
              }
          },
      },
  </code></pre>
  <ul>
  <li>My problem occurs here on <strong>Mutation</strong> when trying to create user with rate limit</li>
  </ul>
  <pre><code>Mutation: {
          async createUser(_, {
              createInput: {
                  name,
                  email,
                  role,
                  password,
                  confirmPassword
              }
          }) {
  
              /****** problem here ******/
              
              const errorMessage = await rateLimiter(
                  { parent, args, context, info },
                  { max: 1, window: '3s' }
              );
              if (errorMessage) throw new Error(errorMessage);
  
              /****** problem here ******/
  
              const { valid, errors } = validateCreateInput(name, email, role, password, confirmPassword);
  
              if (!valid) {
                  throw new UserInputError('Errors', { errors })
              }
  
              const duplicateEmail = await User.findOne({ email });
  
              if (duplicateEmail) {
                  throw new UserInputError('Email is already used', {
                      errors: {
                          email: 'Email is already used'
                      }
                  })
              }
  
              password = await bcrypt.hash(password, 12);
  
              const newUser = new User({
                  name,
                  email,
                  role,
                  password,
                  createdAt: new Date().toISOString()
              })
  
              const res = await newUser.save();
  
              return {
                  ...res._doc,
                  id: res._id
              }
          }
      }
  </code></pre>
  <ul>
  <li>The error that I am getting while creating new user</li>
  </ul>
  <p><a href="https://i.stack.imgur.com/9Hj3v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Hj3v.png" alt="enter image description here" /></a></p>