Skip to content

Commit

Permalink
add option to query multiple locations 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 c99738d
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 @@ -33,6 +33,9 @@ const resolvers = {
const info = handleInfo({ stats })
return { results, info }
},
locationsByIds: async (_, { ids }, { dataSources }) => {
return dataSources.location.locationsByIds({ ids })
},
location: async (_, { id }, { dataSources }) => {
return dataSources.location.location({ id })
},
Expand Down
4 changes: 4 additions & 0 deletions graphql/sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Location extends RESTDataSource {
const data = await this.get('/', { ...filter, page })
return data
}
async locationsByIds({ ids }) {
const data = await this.get('/' + ids)
return Array.isArray(data) ? data : [data]
}
async location({ 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 @@ -22,6 +22,11 @@ const typeDefs = gql`
"""
locations(page: Int, filter: FilterLocation): Locations
"""
Get a list of locations selected by ids
"""
locationsByIds(ids: [ID]): [Location]
"""
Get a specific episode by ID
"""
Expand Down

0 comments on commit c99738d

Please sign in to comment.