diff --git a/src/__mocks__/contactsSchema.js b/src/__mocks__/contactsSchema.js index c75dc2fe..a41a48e2 100644 --- a/src/__mocks__/contactsSchema.js +++ b/src/__mocks__/contactsSchema.js @@ -5,6 +5,7 @@ const ContactsSchema = new Schema( phones: [String], email: String, skype: String, + locationId: Schema.Types.ObjectId, } ); diff --git a/src/__tests__/fieldConverter-test.js b/src/__tests__/fieldConverter-test.js index 780131ca..b7e9f089 100644 --- a/src/__tests__/fieldConverter-test.js +++ b/src/__tests__/fieldConverter-test.js @@ -167,7 +167,12 @@ describe('fieldConverter', () => { }); it('should have embedded fields', () => { - expect(embeddedFields.email).to.be.defined; + expect(embeddedFields.email).to.be.ok; + }); + + it('should have embedded fields with MongoID type, except pseudoID', () => { + expect(embeddedFields.locationId).to.be.ok; + expect(embeddedFields._id).to.be.undefined; }); it('should skip pseudo mongoose _id field', () => { diff --git a/src/fieldsConverter.js b/src/fieldsConverter.js index 3e145e3e..dc5e3a25 100644 --- a/src/fieldsConverter.js +++ b/src/fieldsConverter.js @@ -231,8 +231,9 @@ export function deriveComplexType(field: MongooseFieldT): ComplexTypesT { function removePseudoIdField(typeComposer: TypeComposer): void { // remove pseudo object id mongoose field const gqFields = typeComposer.getFields(); - Object.keys(gqFields).forEach((name) => { - if (gqFields[name].type === GraphQLMongoID) { + const pseudoFieldNames = ['_id']; + pseudoFieldNames.forEach((name) => { + if (gqFields[name] && gqFields[name].type === GraphQLMongoID) { typeComposer.removeField(name); } });