<commit_before>import localLogin from '../authentication/localLogin';
import { ImageType, Image } from './imageType';
import  { buffer2Img, img2Buffer } from '../../tools/img';

export default function getResolvers() {
  const app = this;
  const Recipes = app.service('recipes');
  const Cookbook = app.service('cookbooks');
  const Users = app.service('users');
  const Viewer = app.service('viewer');
  const login = localLogin.bind(app);

  return {
    Image: ImageType,
    User: {
      recipes(user, args, context) {
        return Recipes.find({
          query: {
            authorId: user._id
          }
        });
      },
      cookbooks(user, args, context) {
        return Cookbook.find({
          query: {
            authorId: user._id
          }
        });
      }
    },
    Recipe: {
      author(recipe, args, context) {
        return Users.get(recipe.authorId);
      },
      thumbnail(recipe, {width, height, greyscale}, context) {
        return buffer2Img(recipe.image, {width, height, greyscale});
      },
    },
    Cookbook: {
      author(cookbook, args, context) {
        return Users.get(cookbook.authorId);
      },
      recipes(cookbook, args, context) {
        return Recipes.find({
          query: {
            _id: cookbook.recipes
          }
        });
      },
      thumbnail(recipe, {width, height, greyscale}, context) {
        return buffer2Img(recipe.image, {width, height, greyscale});
      },
    },
    AuthPayload: {
      data(auth, args, context) {
        return auth.data;
      }
    },
    RootQuery: {
      viewer(root, args, context) {
        return Viewer.find(context);
      },
      author(root, { username }, context) {
        return Users.find({
          query: {
            username
          }
        }).then((users) => users[0]);
      },
      authors(root, args, context) {
        return Users.find({})
      },
      recipes(root, args, context) {
        return Recipes.find({});
      },
      recipe(root, {_id}, context) {
        return Recipes.find({
          query: {
            _id,
          }
        });
      },
      cookbooks(root, args, context) {
        return Cookbook.find({});
      },
      cookbook(root, {_id}, context) {
        return Cookbook.find({
          query: {
            _id,
          }
        });
      },
    },

    RootMutation: {
      signUp(root, args, context) {
        return Users.create(args)
      },
      logIn(root, {username, password}, context) {
        return login(username, password);
      },
      createRecipe(root, { recipe, imageUrl }, context) {
        if (!imageUrl) {
          return Recipes.create(recipe, context);
        }
        return img2Buffer(imageUrl).then((image) => {
          const data = recipe;
          data.image = image;
          return Recipes.create(data, context);
        })
      },
    }
  }
}<commit_msg>Rename Resolvers and fix bug<commit_after>import localLogin from '../authentication/localLogin';
import { ImageType, Image } from './imageType';
import  { buffer2Img, img2Buffer } from '../../tools/img';

export default function getResolvers() {
  const app = this;
  const Recipes = app.service('recipes');
  const Cookbooks = app.service('cookbooks');
  const Users = app.service('users');
  const Viewer = app.service('viewer');
  const login = localLogin.bind(app);

  return {
    Image: ImageType,
    User: {
      recipes(user, args, context) {
        return Recipes.find({
          query: {
            authorId: user._id
          }
        });
      },
      cookbooks(user, args, context) {
        return Cookbooks.find({
          query: {
            authorId: user._id
          }
        });
      }
    },
    Recipe: {
      author(recipe, args, context) {
        return Users.get(recipe.authorId);
      },
      thumbnail(recipe, {width, height, greyscale}, context) {
        return buffer2Img(recipe.image, {width, height, greyscale});
      },
    },
    Cookbook: {
      author(cookbook, args, context) {
        return Users.get(cookbook.authorId);
      },
      recipes(cookbook, args, context) {
        return Recipes.find({
          query: {
            _id: cookbook.recipes
          }
        });
      },
      thumbnail(recipe, {width, height, greyscale}, context) {
        return buffer2Img(recipe.image, {width, height, greyscale});
      },
    },
    AuthPayload: {
      data(auth, args, context) {
        return auth.data;
      }
    },
    RootQuery: {
      viewer(root, args, context) {
        return Viewer.find(context);
      },
      author(root, { username }, context) {
        return Users.find({
          query: {
            username
          }
        }).then((users) => users[0]);
      },
      authors(root, args, context) {
        return Users.find({})
      },
      recipes(root, args, context) {
        return Recipes.find({});
      },
      recipe(root, {_id}, context) {
        return Recipes.get(_id);
      },
      cookbooks(root, args, context) {
        return Cookbooks.find({});
      },
      cookbook(root, {_id}, context) {
        return Cookbooks.get(_id);
      },
    },

    RootMutation: {
      signUp(root, args, context) {
        return Users.create(args)
      },
      logIn(root, {username, password}, context) {
        return login(username, password);
      },
      createRecipe(root, { recipe, imageUrl }, context) {
        if (!imageUrl) {
          return Recipes.create(recipe, context);
        }
        return img2Buffer(imageUrl).then((image) => {
          const data = recipe;
          data.image = image;
          return Recipes.create(data, context);
        })
      },
    }
  }
}
{'fraction_non_alphanumeric': 0.13857218031924223, 'fraction_numerical': 0.002104893878266971, 'mean_word_length': 1.835405271009448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7200733', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1696, 'n_words': 356}