I am following along with this Graphql intro https://www.apollographql.com/docs/apollo-server/getting-started/. I've got my files set up (slightly modified), and the base query is working on http://localhost:4000/.
My next question after getting through the basics was, how do I get data based on parameters? I've gotten this far, but the query in playground doesn't return results.
index.js
const typeDefs = gql`
type Item {
name: String
description: String
full_url: String
term: String
}
type Query {
items: [Item]
itemsSearch(term: String!): [Item]
}
`;
const resolvers = {
Query: {
// this works. it is the example from the guide.
items: () => items,
// this doesn't work. `term` is always undefined
itemsSearch: term => {
console.log('term', term);
console.log('items', items);
return items.filter(item => item.title.indexOf(term) > -1 || item.author.indexOf(term) > -1);
},
},
};
Then I'm running this query in playground. (mostly working from https://graphql.org/graphql-js/passing-arguments/)
{
itemsSearch(term: "Rowling") {
title
author
}
}
I get a successful response but no data. As mentioned, logging term in the itemsSearch resolver prints undefined.
Any idea how I can pass that param term to the resolver and get results? Thanks in advance.
itemsSearch: (parent, { term }) => {? - pzaengertermnow. Thank you. Add as an answer, if you'd like me to accept it. - Tayler