-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-query.js
67 lines (60 loc) · 1.93 KB
/
test-query.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
const graphql = require('graphql');
const Collection1Schema = require('./collection1Schema-model');
const Collection2Schema = require('./collection2Schema-model');
const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json');
const {
GraphQLObjectType, GraphQLString,
GraphQLID, GraphQLInt, GraphQLSchema,
GraphQLList, GraphQLNonNull, GraphQLBoolean, GraphQL
} = graphql;
const Collection1SchemaType = new GraphQLObjectType({
name: 'collection1',
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
// status: { type: GraphQLBoolean },
mock_data: { type: GraphQLJSONObject },
})
});
const Collection2SchemaType = new GraphQLObjectType({
name: 'collection2',
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
status: { type: GraphQLBoolean }
})
});
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
collection1: {
type: Collection1SchemaType,
args: { id: { type: GraphQLID } },
resolve(parent, args) {
return Collection1Schema.findOne({ id: args.id });
}
},
collections1: {
type: new GraphQLList(Collection1SchemaType),
resolve(parent, args) {
return Collection1.find({});
}
},
collection2: {
type: Collection2SchemaType,
args: { id: { type: GraphQLID } },
resolve(parent, args) {
return Collection2Schema.findOne({ id: args.id });
}
},
collections2: {
type: new GraphQLList(Collection2SchemaType),
resolve(parent, args) {
return Collection2Schema.find({});
}
}
}
});
module.exports = new GraphQLSchema({
query: RootQuery
});