Last active
January 4, 2018 13:05
-
-
Save dave-nicholas/05f698dd951f8a9fdfbf5df29fa8ee62 to your computer and use it in GitHub Desktop.
apollo server resolvers for blog article
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
const resolvers = { | |
River: { | |
async streams(river) { | |
return await Streams.find({ riverId: river.id }).toArray(); | |
} | |
}, | |
Stream: { | |
async river(stream) { | |
return await Streams.findOne({ riverId: stream.riverId }); | |
}, | |
async brooks(stream) { | |
return await Brooks.find({ streamId: stream.id }).toArray(); | |
} | |
}, | |
Brook: { | |
async stream(brook) { | |
return await Brooks.findOne({ streamId: brook.streamId }); | |
} | |
}, | |
Query: { | |
async river(_, { id }) { | |
return await River.find({ id }).toArray(); //find using mongodb | |
}, | |
async rivers() { | |
return River.find({}).toArray(); //find using mongodb | |
}, | |
async BrooksByRiverName(_, { name }) { | |
//This search uses algolia to defer full text searches | |
const { hits } = await index.search(name); | |
return !!hits.length | |
? Brook.find({ id: hits.map(hit => hit.brookId) }).toArray() | |
: null; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment