a tiny bit of refactoring (separating types to own files)
This commit is contained in:
1 parent
f0741afd21
commit
e07f0ba077
9 files changed
+230
-166
No files matched your search
@@ -1,166 +0,0 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLSchema,
|
||||
GraphQLID,
|
||||
GraphQLString,
|
||||
GraphQLInt,
|
||||
GraphQLList,
|
||||
GraphQLNonNull
|
||||
} from 'graphql'
|
||||
import { slugify } from './utils/functions'
|
||||
import Competition from './models/competition'
|
||||
|
||||
const PlotterType = new GraphQLObjectType({
|
||||
name: 'Plotter',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
host: { type: GraphQLString },
|
||||
repo: { type: GraphQLString },
|
||||
moduleName: { type: GraphQLString }
|
||||
})
|
||||
})
|
||||
|
||||
const RuleType = new GraphQLObjectType({
|
||||
name: 'Rule',
|
||||
fields: () => ({
|
||||
number: { type: GraphQLInt },
|
||||
title: { type: GraphQLString },
|
||||
description: { type: GraphQLString }
|
||||
})
|
||||
})
|
||||
|
||||
const ParticipantType = new GraphQLObjectType({
|
||||
name: 'Participant',
|
||||
fields: () => ({
|
||||
devTeam: { type: GraphQLString },
|
||||
bot: { type: GraphQLString },
|
||||
release: { type: GraphQLString }
|
||||
})
|
||||
})
|
||||
|
||||
const OtherPrizeType = new GraphQLObjectType({
|
||||
name: 'OtherPrize',
|
||||
fields: () => ({
|
||||
condition: { type: GraphQLString },
|
||||
amount: { type: GraphQLInt },
|
||||
asset: { type: GraphQLString }
|
||||
})
|
||||
})
|
||||
|
||||
const PrizeType = new GraphQLObjectType({
|
||||
name: 'Prize',
|
||||
fields: () => ({
|
||||
position: { type: GraphQLInt },
|
||||
algoPrize: { type: GraphQLInt },
|
||||
otherPrizes: {
|
||||
type: new GraphQLList(OtherPrizeType),
|
||||
resolve (parent, args) {
|
||||
return parent.otherPrizes
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const CompetitionType = new GraphQLObjectType({
|
||||
name: 'Competition',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLID },
|
||||
displayName: { type: GraphQLString },
|
||||
host: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
startDatetime: { type: GraphQLString },
|
||||
finishDatetime: { type: GraphQLString },
|
||||
formula: { type: GraphQLString },
|
||||
plotter: {
|
||||
type: PlotterType,
|
||||
resolve (parent, args) {
|
||||
return parent.plotter
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
type: new GraphQLList(RuleType),
|
||||
resolve (parent, args) {
|
||||
return parent.rules
|
||||
}
|
||||
},
|
||||
participants: {
|
||||
type: new GraphQLList(ParticipantType),
|
||||
resolve (parent, args) {
|
||||
return parent.participants
|
||||
}
|
||||
},
|
||||
prizes: {
|
||||
type: new GraphQLList(PrizeType),
|
||||
resolve (parent, args) {
|
||||
return parent.prizes
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: {
|
||||
competitions: {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
resolve (parent, args, context) {
|
||||
return Competition.find()
|
||||
}
|
||||
},
|
||||
competitionsByHost: {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
args: {
|
||||
host: { type: new GraphQLNonNull(GraphQLString) }
|
||||
},
|
||||
resolve (parent, args, context) {
|
||||
return Competition.find({
|
||||
host: args.host
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const Mutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
fields: {
|
||||
hostCompetition: {
|
||||
type: CompetitionType,
|
||||
args: {
|
||||
displayName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
description: { type: new GraphQLNonNull(GraphQLString) },
|
||||
startDatetime: { type: new GraphQLNonNull(GraphQLString) },
|
||||
finishDatetime: { type: new GraphQLNonNull(GraphQLString) },
|
||||
formula: { type: new GraphQLNonNull(GraphQLString) }
|
||||
},
|
||||
resolve (parent, args, context) {
|
||||
// let authIdOnSession = context.user.sub
|
||||
let authIdOnSession = 'some-id'
|
||||
let newCompetition = new Competition({
|
||||
host: authIdOnSession,
|
||||
displayName: args.displayName,
|
||||
description: args.description,
|
||||
// startDatetime: args.startDatetime,
|
||||
// finishDatetime: args.finishDatetime,
|
||||
formula: args.formula
|
||||
})
|
||||
newCompetition.codeName = slugify(newCompetition.displayName) + '-' + newCompetition._id
|
||||
return new Promise((resolve, reject) => {
|
||||
newCompetition.save((err) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
resolve(newCompetition)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const Schema = new GraphQLSchema({
|
||||
query: RootQuery,
|
||||
mutation: Mutation
|
||||
})
|
||||
|
||||
export default Schema
|
||||
@@ -0,0 +1,78 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLSchema,
|
||||
GraphQLString,
|
||||
GraphQLList,
|
||||
GraphQLNonNull
|
||||
} from 'graphql'
|
||||
import { slugify } from '../utils/functions'
|
||||
|
||||
import Competition from '../models/competition'
|
||||
import { CompetitionType } from './types'
|
||||
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: {
|
||||
competitions: {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
resolve (parent, args, context) {
|
||||
return Competition.find()
|
||||
}
|
||||
},
|
||||
competitionsByHost: {
|
||||
type: new GraphQLList(CompetitionType),
|
||||
args: {
|
||||
host: { type: new GraphQLNonNull(GraphQLString) }
|
||||
},
|
||||
resolve (parent, args, context) {
|
||||
return Competition.find({
|
||||
host: args.host
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const Mutation = new GraphQLObjectType({
|
||||
name: 'Mutation',
|
||||
fields: {
|
||||
hostCompetition: {
|
||||
type: CompetitionType,
|
||||
args: {
|
||||
displayName: { type: new GraphQLNonNull(GraphQLString) },
|
||||
description: { type: new GraphQLNonNull(GraphQLString) },
|
||||
startDatetime: { type: new GraphQLNonNull(GraphQLString) },
|
||||
finishDatetime: { type: new GraphQLNonNull(GraphQLString) },
|
||||
formula: { type: new GraphQLNonNull(GraphQLString) }
|
||||
},
|
||||
resolve (parent, args, context) {
|
||||
// let authIdOnSession = context.user.sub
|
||||
let authIdOnSession = 'some-id'
|
||||
let newCompetition = new Competition({
|
||||
host: authIdOnSession,
|
||||
displayName: args.displayName,
|
||||
description: args.description,
|
||||
// startDatetime: args.startDatetime,
|
||||
// finishDatetime: args.finishDatetime,
|
||||
formula: args.formula
|
||||
})
|
||||
newCompetition.codeName = slugify(newCompetition.displayName) + '-' + newCompetition._id
|
||||
return new Promise((resolve, reject) => {
|
||||
newCompetition.save((err) => {
|
||||
if (err) reject(err)
|
||||
else {
|
||||
resolve(newCompetition)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const Schema = new GraphQLSchema({
|
||||
query: RootQuery,
|
||||
mutation: Mutation
|
||||
})
|
||||
|
||||
export default Schema
|
||||
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLList,
|
||||
GraphQLID
|
||||
} from 'graphql'
|
||||
import {
|
||||
PlotterType,
|
||||
RuleType,
|
||||
ParticipantType,
|
||||
PrizeType
|
||||
} from './index'
|
||||
|
||||
const CompetitionType = new GraphQLObjectType({
|
||||
name: 'Competition',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLID },
|
||||
displayName: { type: GraphQLString },
|
||||
host: { type: GraphQLString },
|
||||
description: { type: GraphQLString },
|
||||
startDatetime: { type: GraphQLString },
|
||||
finishDatetime: { type: GraphQLString },
|
||||
formula: { type: GraphQLString },
|
||||
plotter: {
|
||||
type: PlotterType,
|
||||
resolve (parent, args) {
|
||||
return parent.plotter
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
type: new GraphQLList(RuleType),
|
||||
resolve (parent, args) {
|
||||
return parent.rules
|
||||
}
|
||||
},
|
||||
participants: {
|
||||
type: new GraphQLList(ParticipantType),
|
||||
resolve (parent, args) {
|
||||
return parent.participants
|
||||
}
|
||||
},
|
||||
prizes: {
|
||||
type: new GraphQLList(PrizeType),
|
||||
resolve (parent, args) {
|
||||
return parent.prizes
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
export default CompetitionType
|
||||
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLInt
|
||||
} from 'graphql'
|
||||
|
||||
const OtherPrizeType = new GraphQLObjectType({
|
||||
name: 'OtherPrize',
|
||||
fields: () => ({
|
||||
condition: { type: GraphQLString },
|
||||
amount: { type: GraphQLInt },
|
||||
asset: { type: GraphQLString }
|
||||
})
|
||||
})
|
||||
|
||||
export default OtherPrizeType
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql'
|
||||
|
||||
const ParticipantType = new GraphQLObjectType({
|
||||
name: 'Participant',
|
||||
fields: () => ({
|
||||
devTeam: { type: GraphQLString },
|
||||
bot: { type: GraphQLString },
|
||||
release: { type: GraphQLString }
|
||||
})
|
||||
})
|
||||
|
||||
export default ParticipantType
|
||||
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLString
|
||||
} from 'graphql'
|
||||
|
||||
const PlotterType = new GraphQLObjectType({
|
||||
name: 'Plotter',
|
||||
fields: () => ({
|
||||
codeName: { type: GraphQLString },
|
||||
host: { type: GraphQLString },
|
||||
repo: { type: GraphQLString },
|
||||
moduleName: { type: GraphQLString }
|
||||
})
|
||||
})
|
||||
|
||||
export default PlotterType
|
||||
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLList,
|
||||
GraphQLInt
|
||||
} from 'graphql'
|
||||
import { OtherPrizeType } from './index'
|
||||
|
||||
const PrizeType = new GraphQLObjectType({
|
||||
name: 'Prize',
|
||||
fields: () => ({
|
||||
position: { type: GraphQLInt },
|
||||
algoPrize: { type: GraphQLInt },
|
||||
otherPrizes: {
|
||||
type: new GraphQLList(OtherPrizeType),
|
||||
resolve (parent, args) {
|
||||
return parent.otherPrizes
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
export default PrizeType
|
||||
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
GraphQLObjectType,
|
||||
GraphQLInt,
|
||||
GraphQLString
|
||||
} from 'graphql'
|
||||
|
||||
const RuleType = new GraphQLObjectType({
|
||||
name: 'Rule',
|
||||
fields: () => ({
|
||||
number: { type: GraphQLInt },
|
||||
title: { type: GraphQLString },
|
||||
description: { type: GraphQLString }
|
||||
})
|
||||
})
|
||||
|
||||
export default RuleType
|
||||
@@ -0,0 +1,16 @@
|
||||
import PlotterType from './Plotter'
|
||||
import RuleType from './Rule'
|
||||
import ParticipantType from './Participant'
|
||||
import OtherPrizeType from './OtherPrize'
|
||||
import PrizeType from './Prize'
|
||||
import CompetitionType from './Competition'
|
||||
|
||||
export {
|
||||
PlotterType,
|
||||
RuleType,
|
||||
ParticipantType,
|
||||
OtherPrizeType,
|
||||
PrizeType,
|
||||
CompetitionType
|
||||
}
|
||||
export default CompetitionType
|
||||
Reference in new issue
Block a user