HomeToolsAbout

Resolver Search/Filter

What is it

Search = Filter

How to implement

# Schema type Query { album(id: ID!): Album albums(genre: Genre): [Album]! } # Query query GetRockAlbums { album(id: "1") { title genre artist { name } } albums(genre: "Rock") { title genre artist { name } } }
const resolvers = { Query: { album: (parent, args, context, info) => { const { id } = args; return context.db.Albums.find((a) => a.id == id) }, albums: (parent, args, context, info) => { const { genre } = args; return context.db.Albums.filter((a) => a.genre == genre) } } }
AboutContact