/
schemaWithArray.spec.js
56 lines (48 loc) · 1.43 KB
/
schemaWithArray.spec.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
import mongoose from 'mongoose';
import { GraphQLInt, GraphQLList, GraphQLObjectType, GraphQLString } from 'graphql';
import mongooseSchemaToGraphQL, {
generateDescriptionForSubField,
generateNameForSubField,
} from '../lib/index.min';
import { getRidOfThunks } from '../tools/util';
test('generates schemas with arrays correctly', () => {
const NAME = 'ArrayTestSchema';
const DESCRIPTION = 'Testing';
const WhateverSchema = new mongoose.Schema({
a: Number,
b: Number,
});
const Schema = new mongoose.Schema({
something: String,
whatever: [WhateverSchema],
});
const ExpectedType = getRidOfThunks(
mongooseSchemaToGraphQL({
name: NAME,
class: 'GraphQLObjectType',
description: DESCRIPTION,
schema: Schema,
exclude: ['_id'],
}),
);
const ReceivedType = getRidOfThunks(
(new GraphQLObjectType({
name: NAME,
description: DESCRIPTION,
fields: () => ({
something: { type: GraphQLString },
whatever: {
type: new GraphQLList(new GraphQLObjectType({
name: generateNameForSubField(NAME, 'whatever'),
description: generateDescriptionForSubField(NAME, 'whatever'),
fields: () => ({
a: { type: GraphQLInt },
b: { type: GraphQLInt },
}),
})),
},
}),
})),
);
expect(JSON.stringify(ExpectedType)).toEqual(JSON.stringify(ReceivedType));
});