Created
October 8, 2015 06:57
-
-
Save nickretallack/67aae5b457b3309bc663 to your computer and use it in GitHub Desktop.
Resolvers for a Pokemon GraphQL API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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