forked from terrestris/gondolin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphql.ts
110 lines (100 loc) · 2.01 KB
/
graphql.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLNonNull,
GraphQLInt,
GraphQLList,
GraphQLString
} from 'graphql';
import sequelize from './sequelize';
const {
Application,
User
} = sequelize.models;
import {
attributeFields,
resolver,
JSONType
} from 'graphql-sequelize';
import Layer from './models/Layer';
const defaultListArgs = {
limit: {
type: GraphQLInt
},
order: {
type: GraphQLString
},
where: {
// TODO: I wonder why we need to add `default`
type: JSONType.default
}
};
const defaultSingleArgs = {
id: {
type: new GraphQLNonNull(GraphQLInt)
}
};
const applicationType = new GraphQLObjectType({
name: 'Application',
description: 'An application',
fields: attributeFields(Application)
});
const layerType = new GraphQLObjectType({
name: 'Layer',
description: 'A layer',
fields: attributeFields(Layer)
});
const userType = new GraphQLObjectType({
name: 'User',
description: 'An user',
fields: attributeFields(User),
});
export default new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
applications: {
type: new GraphQLList(applicationType),
args: {
...defaultListArgs
},
resolve: resolver(Application)
},
application: {
type: applicationType,
args: {
...defaultSingleArgs
},
resolve: resolver(Application)
},
layers: {
type: new GraphQLList(layerType),
args: {
...defaultListArgs
},
resolve: resolver(Layer)
},
layer: {
type: layerType,
args: {
...defaultSingleArgs
},
resolve: resolver(Layer)
},
users: {
type: new GraphQLList(userType),
args: {
...defaultListArgs
},
resolve: resolver(User)
},
user: {
type: userType,
args: {
...defaultSingleArgs
},
resolve: resolver(User)
}
}
})
});