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) {
    let entity;
    try {
      entity = await strapi.query('user', 'users-permissions').findOne({
        email: 'test@test.co.uk'
    } catch (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: {
  }) {
    user {

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?