Skip to content

Commit e4fde58

Browse files
committed
fix: required fields in embedded documents became optional for filter args and became optional for update(ById|One|Many) resolvers. All such embedded types are clonned and have its own unique names.
1 parent a0a8c39 commit e4fde58

39 files changed

+305
-95
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ lib/*
22
es/*
33
mjs/*
44
node8/*
5-
flow-typed
5+
jest.config.js

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module.exports = {
88
diagnostics: false,
99
},
1010
},
11+
moduleNameMapper: {
12+
'^src/(.*)$': '<rootDir>/src/$1',
13+
},
1114
moduleFileExtensions: ['ts', 'js'],
1215
transform: {
1316
'^.+\\.ts$': 'ts-jest',

src/__mocks__/contactsSchema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { Schema } from './mongooseCommon';
33

44
const ContactsSchema: SchemaType<any> = new Schema({
55
phones: [String],
6-
email: String,
6+
email: {
7+
type: String,
8+
required: true,
9+
},
710
skype: String,
811
locationId: Schema.Types.ObjectId,
912
});

src/__mocks__/userModel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ export interface IUser extends Document {
136136
someDynamic?: any;
137137
skills?: string[];
138138
relocation?: boolean;
139+
contacts: {
140+
email: string;
141+
};
139142
}
140143

141144
const UserModel = mongoose.model<IUser>('User', UserSchema);

src/__tests__/github_issues/219-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ beforeAll(async () => {
99
await UserModel.create({
1010
name: 'AAAAA',
1111
age: 10,
12+
contacts: { email: '1@1.com' },
1213
});
1314
await UserModel.create({
1415
name: 'BBBBB',
1516
age: 20,
17+
contacts: { email: '2@2.com' },
1618
});
1719
});
1820
afterAll(() => UserModel.base.disconnect());

src/__tests__/github_issues/92-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('issue #92 - How to verify the fields?', () => {
3030
schema,
3131
`
3232
mutation {
33-
addUser(record: { name: "User1", age: 30 }) {
33+
addUser(record: { name: "User1", age: 30, contacts: { email: "1@1.com" } }) {
3434
record {
3535
name
3636
age
@@ -47,7 +47,7 @@ describe('issue #92 - How to verify the fields?', () => {
4747
schema,
4848
`
4949
mutation {
50-
addUser(record: { name: "User1", age: 10 }) {
50+
addUser(record: { name: "User1", age: 10, contacts: { email: "1@1.com" } }) {
5151
record {
5252
name
5353
age

src/__tests__/github_issues/93-test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ describe('issue #93', () => {
2323
_id: '100000000000000000000301',
2424
name: 'User301',
2525
age: 301,
26+
contacts: { email: '1@1.com' },
2627
});
2728
await UserModel.create({
2829
_id: '100000000000000000000302',
2930
name: 'User302',
3031
age: 302,
3132
gender: 'male',
33+
contacts: { email: '2@2.com' },
3234
});
3335
await UserModel.create({
3436
_id: '100000000000000000000303',
3537
name: 'User303',
3638
age: 302,
3739
gender: 'female',
40+
contacts: { email: '3@3.com' },
3841
});
3942

4043
const res = await graphql.graphql(

src/__tests__/integration-test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('integration tests', () => {
2121

2222
const user = new UserModel({
2323
name: 'Test empty subDoc',
24+
contacts: { email: 'mail' },
2425
});
2526
await user.save();
2627
const result: any = await graphql(
@@ -59,6 +60,7 @@ describe('integration tests', () => {
5960

6061
const user2 = new UserModel({
6162
name: 'Test non empty subDoc',
63+
contacts: { email: 'mail' },
6264
subDoc: { field2: { field21: 'ok' } },
6365
});
6466
await user2.save();
@@ -92,6 +94,7 @@ describe('integration tests', () => {
9294
const UserTC = composeWithMongoose(UserModel, { schemaComposer });
9395
const user = new UserModel({
9496
name: 'nodkz',
97+
contacts: { email: 'mail' },
9598
someDynamic: {
9699
a: 123,
97100
b: [1, 2, true, false, 'ok'],
@@ -145,6 +148,7 @@ describe('integration tests', () => {
145148
gender: 'male',
146149
skills: ['a', 'b', 'c'],
147150
relocation: true,
151+
contacts: { email: 'mail' },
148152
});
149153
});
150154

src/resolvers/__tests__/connection-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ describe('connection() resolver', () => {
126126
skills: ['js', 'ruby', 'php', 'python'],
127127
gender: 'male',
128128
relocation: true,
129+
contacts: { email: 'mail' },
129130
});
130131

131132
user2 = new UserModel({
132133
name: 'userName2',
133134
skills: ['go', 'erlang'],
134135
gender: 'female',
135136
relocation: false,
137+
contacts: { email: 'mail' },
136138
});
137139

138140
await user1.save();

src/resolvers/__tests__/count-test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ describe('count() ->', () => {
2727
skills: ['js', 'ruby', 'php', 'python'],
2828
gender: 'male',
2929
relocation: true,
30+
contacts: {
31+
email: '`1@1.com',
32+
},
3033
});
3134

3235
user2 = new UserModel({
3336
name: 'userName2',
3437
skills: ['go', 'erlang'],
3538
gender: 'female',
3639
relocation: false,
40+
contacts: {
41+
email: '`2@2.com',
42+
},
3743
});
3844

3945
await user1.save();
@@ -50,6 +56,20 @@ describe('count() ->', () => {
5056
const resolver = count(UserModel, UserTC);
5157
expect(resolver.hasArg('filter')).toBe(true);
5258
});
59+
60+
it('required model fields (filter.contacts.email) should be optional in filter arg', () => {
61+
const resolver = count(UserModel, UserTC);
62+
expect(resolver.getArgITC('filter').getFieldITC('contacts').toSDL({ omitDescriptions: true }))
63+
.toMatchInlineSnapshot(`
64+
"input FilterUserContactsInput {
65+
phones: [String]
66+
email: String
67+
skype: String
68+
locationId: MongoID
69+
_id: MongoID
70+
}"
71+
`);
72+
});
5373
});
5474

5575
describe('Resolver.resolve():Promise', () => {

0 commit comments

Comments
 (0)