Skip to content

Commit

Permalink
add option to query multiple episodes by ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Ey-Jay committed Aug 21, 2020
1 parent 164051e commit 96737b1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const resolvers = {
const info = handleInfo({ stats })
return { results, info }
},
episodesByIds: async (_, { ids }, { dataSources }) => {
return dataSources.episode.episodesByIds({ ids })
},
episode: async (_, { id }, { dataSources }) => {
return dataSources.episode.episode({ id })
},
Expand Down
4 changes: 4 additions & 0 deletions graphql/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Episode extends RESTDataSource {
const data = await this.get('/', { ...filter, page })
return data
}
async episodesByIds({ ids }) {
const data = await this.get('/' + ids)
return Array.isArray(data) ? data : [data]
}
async episode({ id }) {
const data = await this.get('/' + id)
return data
Expand Down
5 changes: 5 additions & 0 deletions graphql/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const typeDefs = gql`
Get the list of all episodes
"""
episodes(page: Int, filter: FilterEpisode): Episodes
"""
Get a list of episodes selected by ids
"""
episodesByIds(ids: [ID]): [Episode]
}
type Characters {
Expand Down

0 comments on commit 96737b1

Please sign in to comment.