Skip to content

Commit

Permalink
Make return values non-nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
juusaw committed Feb 15, 2019
1 parent 324cd4f commit 62ecd87
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,48 @@ interface RollStatsParent extends RollParent {}
const RollStatsType = new GraphQLObjectType({
name: 'Statistics',
fields: {
average: { type: GraphQLFloat, resolve: (parent: RollStatsParent) => calculateMean(parent.roll) },
max: { type: GraphQLInt, resolve: (parent: RollStatsParent) => calculateMax(parent.roll)},
min: { type: GraphQLInt, resolve: (parent: RollStatsParent) => calculateMin(parent.roll)}
average: {
type: new GraphQLNonNull(GraphQLFloat),
resolve: (parent: RollStatsParent) => calculateMean(parent.roll)
},
max: {
type: new GraphQLNonNull(GraphQLInt),
resolve: (parent: RollStatsParent) => calculateMax(parent.roll)
},
min: {
type: new GraphQLNonNull(GraphQLInt),
resolve: (parent: RollStatsParent) => calculateMin(parent.roll)
}
}
})

interface RollResultParent extends RollParent { rollResult: DieRoll[] }
const RollResultType = new GraphQLObjectType({
name: 'Results',
fields: {
total: { type: GraphQLInt, resolve: (parent: RollResultParent) => countResult(parent.rollResult)},
details: { type: new GraphQLList(GraphQLInt), resolve: (parent: RollResultParent) => parent.rollResult.map(({result}) => result) }
total: {
type: new GraphQLNonNull(GraphQLInt),
resolve: (parent: RollResultParent) => countResult(parent.rollResult)
},
details: {
type: new GraphQLList(GraphQLInt),
resolve: (parent: RollResultParent) => parent.rollResult.map(({result}) => result)
}
}
})

interface RollParent { roll: Dice[] }
const RollType = new GraphQLObjectType({
name: 'Roll',
fields: {
result: { type: RollResultType, resolve: (parent: RollParent) => ({...parent, rollResult: rollDice(parent.roll)}) },
statistics: { type: RollStatsType, resolve: (parent: RollParent) => parent }
result: {
type: new GraphQLNonNull(RollResultType),
resolve: (parent: RollParent) => ({...parent, rollResult: rollDice(parent.roll)})
},
statistics: {
type: new GraphQLNonNull(RollStatsType),
resolve: (parent: RollParent) => parent
}
}
})

Expand Down

0 comments on commit 62ecd87

Please sign in to comment.