Skip to content

Commit

Permalink
fix(type): fix embedded object reference Type creation (#132)
Browse files Browse the repository at this point in the history
fixes #131
  • Loading branch information
yoadsn authored and András Tóth committed Aug 16, 2016
1 parent a5b1298 commit 436e56e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 5 additions & 1 deletion fixture/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ const UserSchema = new mongoose.Schema({
nums: [Number],
subsub: {
bar: Number
}
},
subref: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
},
},
subArray: [{
foo: String,
Expand Down
17 changes: 15 additions & 2 deletions src/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ describe('e2e', () => {
age: 28,
mother: motherUser._id,
friends: [user1._id],
objectIds: [user1._id]
objectIds: [user1._id],
sub: {
subref: motherUser._id
}
});

await user2.save();
Expand Down Expand Up @@ -87,6 +90,11 @@ describe('e2e', () => {
}
}
objectIds
sub {
subref {
name
}
}
}
}`);

Expand All @@ -109,7 +117,12 @@ describe('e2e', () => {
}
}]
},
objectIds: [user1._id.toString()]
objectIds: [user1._id.toString()],
sub: {
subref: {
name: 'Mother'
}
}
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/type/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function getTypes(graffitiModels) {
path.reduce((parent, segment, idx) => {
if (parent[segment]) {
if (parent[segment].type instanceof GraphQLObjectType) {
parent = parent[segment].type.getFields();
parent = getTypeFields(parent[segment].type);
} else if (parent[segment].type instanceof GraphQLList &&
parent[segment].type.ofType instanceof GraphQLObjectType) {
parent = getTypeFields(parent[segment].type.ofType);
Expand Down
2 changes: 1 addition & 1 deletion src/type/type.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('type', () => {
const fields = userType._typeConfig.fields();

expect(fields.mother.type).to.be.equal(userType);
expect(fields.sub.type._fields.subsub.type._fields.sister.type).to.be.equal(userType);
expect(fields.sub.type._typeConfig.fields().subsub.type._typeConfig.fields().sister.type).to.be.equal(userType);
expect(fields.subArray.type.ofType._typeConfig.fields().brother.type).to.be.equal(userType);

// connection type
Expand Down

0 comments on commit 436e56e

Please sign in to comment.