I'm new to graphql and i'm trying to find a single fish by the name I pass into the query. I feel like what I have is close, but it is still returning null in the query and I'm not sure why. Any help would be appreciated!
Here is the dummy data I have in memory:
const fish = [
{ id: 1, name: 'bitterling', available: ['march', 'april', 'may'], amountCaught: 0, sellingPrice: 200 },
{ id: 2, name: 'black bass', available: ['june', 'july', 'august'], amountCaught: 123, sellingPrice: 1000 },
{ id: 3, name: 'koi', available: ['march', 'april', 'feburary'], amountCaught: 12, sellingPrice: 4000 }
]
Schema:
type Query {
fish: [Fish!]!
singleFish(name: String): Fish
}
type Fish {
id: ID!
name: String!
available: [String]
amountCaught: Int
sellingPrice: Int
}
Resolvers:
const resolvers = {
Query: {
fish: () => fish,
singleFish: (parent, args) => fish.filter(i => i.name === args.name)
}
}
}
Query in graphiql:
{
singleFish(name: "bitterling") {
amountCaught
}
}
Result:
{
"data": {
"singleFish": {
"amountCaught": null
}
}
}