Skip to content

Commit

Permalink
fix(FieldsConverter): Pass fields with MongoID type in Embedded Schem…
Browse files Browse the repository at this point in the history
…as (except _id)
  • Loading branch information
nodkz committed Oct 26, 2016
1 parent c1f1850 commit a8baac5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/__mocks__/contactsSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const ContactsSchema = new Schema(
phones: [String],
email: String,
skype: String,
locationId: Schema.Types.ObjectId,
}
);

Expand Down
7 changes: 6 additions & 1 deletion src/__tests__/fieldConverter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/fieldsConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down

0 comments on commit a8baac5

Please sign in to comment.