Override default strapi-plugin-users-permissions createUser resolver

Hello, I am trying to override the default createUser resolver from the strapi-plugin-users-permissions in graphql and seem to be getting a strange error. I have create a user.js file in "/extensions/users-permissions/controllers and have added the following content:

  async create(ctx) {
    console.log('testing');
    let entity;
    try {
      entity = await strapi.query('user', 'users-permissions').findOne({
        email: 'test@test.co.uk'
      });
    } catch (e) {
      console.log('---error---');
      console.log(e);
    }
    return {
      user: entity
    };
  }
};

For now the resolver just queries an existing user and tries to return it from the following query:

  createUser(input: {
    data: {
      email:"asssd@asd.com",
      username:"asssd@asd.com",
    }
  }) {
    user {
      email
    }
  }
}

I am however getting the following error message Cannot read property 'toJSON' of undefined

The error appears to be coming from here node_modules/strapi-plugin-users-permissions/config/schema.graphql.js on line 149. Here is the content snippet of that file:

createUser: {
        description: 'Create a new user',
        resolverOf: 'plugins::users-permissions.user.create',
        resolver: async (obj, options, { context }) => {
          context.params = _.toPlainObject(options.input.where);
          context.request.body = _.toPlainObject(options.input.data);

          await strapi.plugins['users-permissions'].controllers.user.create(context);

          return {
            user: context.body.toJSON ? context.body.toJSON() : context.body,
          };
        },
      },

any ideas why i’m getting this error?