-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcampaign.js
68 lines (58 loc) · 1.42 KB
/
campaign.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { makeExecutableSchema } from 'graphql-tools';
import Campaign from 'models/campaign';
import schemaScopeGate from 'services/schemaScopeGate';
const typeDefs = `
type GameSetting {
minPlayers: Int!,
maxPlayers: Int!,
skillLevel: Int!,
postingFrequency: Int!
}
type Campaign {
id: ID!,
title: String!,
scenario: String!,
overview: String!,
gameSettings: GameSetting!
}
# queries
type Query {
campaigns: [Campaign],
campaign(id: ID!): Campaign!
}
# mutations
type Mutation {
createCampaign(input: CreateCampaignInput): Campaign
}
input CreateCampaignInput {
title: String!,
scenario: String!,
overview: String!,
gameSettings: GameSettingInput!
}
input GameSettingInput {
minPlayers: Int!,
maxPlayers: Int!,
skillLevel: Int!,
postingFrequency: Int!
}
`;
const resolvers = {
Query: {
campaign: (obj, { id }, context) =>
schemaScopeGate(['read:messages'], context, () =>
Campaign.query().findById(id)),
campaigns: (obj, params, context) =>
schemaScopeGate(['read:messages'], context, () =>
Campaign.query())
},
Mutation: {
createCampaign: (obj, { input }, context) =>
schemaScopeGate(['write:messages'], context, () =>
Campaign
.query()
.insert(input)
.returning('*'))
}
};
export default makeExecutableSchema({ typeDefs, resolvers });