30 lines
566 B
JavaScript
30 lines
566 B
JavaScript
import {
|
|
GraphQLBoolean,
|
|
GraphQLList
|
|
} from 'graphql'
|
|
import { epoch } from '../../utils/functions'
|
|
import { CompetitionType } from '../types'
|
|
import Competition from '../../models/competition'
|
|
|
|
const args = {
|
|
includeOld: { type: GraphQLBoolean }
|
|
}
|
|
|
|
const resolve = (parent, { includeOld }, context) => {
|
|
return Competition.find(
|
|
Object.assign(
|
|
{},
|
|
includeOld ? {} : { finishDatetime: { $gt: epoch() } }
|
|
))
|
|
}
|
|
|
|
const query = {
|
|
competitions: {
|
|
type: new GraphQLList(CompetitionType),
|
|
args,
|
|
resolve
|
|
}
|
|
}
|
|
|
|
export default query
|