Adding a query to get a single Event using a designator
This commit is contained in:
1 parent
dc10e4d629
commit
2387af9276
2 files changed
+37
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
GraphQLNonNull,
|
||||
GraphQLID
|
||||
} from 'graphql'
|
||||
import { DatabaseError } from '../../errors'
|
||||
import { EventType } from '../types'
|
||||
import { Event } from '../../models'
|
||||
|
||||
const args = {
|
||||
designator: { type: new GraphQLNonNull(GraphQLID) }
|
||||
}
|
||||
|
||||
const resolve = (parent, { designator }, context) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
Event.findOne({ designator }).exec((err, event) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else if (!event) {
|
||||
reject(new DatabaseError('None of the events respond to that designator'))
|
||||
} else {
|
||||
resolve(event)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const query = {
|
||||
event: {
|
||||
type: EventType,
|
||||
args,
|
||||
resolve
|
||||
}
|
||||
}
|
||||
|
||||
export default query
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
GraphQLObjectType
|
||||
} from 'graphql'
|
||||
|
||||
import EventQuery from './Event'
|
||||
import EventsQuery from './Events'
|
||||
import EventsByHostQuery from './EventsByHost'
|
||||
import EventsByTeamQuery from './EventsByTeam'
|
||||
@@ -11,6 +12,7 @@ import PlottersQuery from './Plotters'
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: Object.assign(
|
||||
EventQuery,
|
||||
EventsQuery,
|
||||
EventsByHostQuery,
|
||||
EventsByTeamQuery,
|
||||
|
||||
Reference in new issue
Block a user