Skip to content

Instantly share code, notes, and snippets.

@nickretallack
Created October 8, 2015 06:57
Show Gist options
  • Save nickretallack/67aae5b457b3309bc663 to your computer and use it in GitHub Desktop.
Save nickretallack/67aae5b457b3309bc663 to your computer and use it in GitHub Desktop.
Resolvers for a Pokemon GraphQL API
let Users = []
function getUser(name) {
return Users.find(user => user.name == name)
}
function upsertUser(name) {
let user = getUser(name)
if (!user) {
user = {
name: name,
created: 123,
caught: []
};
Users.push(user);
}
return user;
}
function caughtPokemon(name, pokemon) {
let user = getUser(name);
let the_pokemon = Pokemon.find(x => x.name == pokemon);
user.caught.push(the_pokemon);
return user;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment