Skip to content

Commit

Permalink
feat(schema): support array of primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton committed Jul 26, 2015
1 parent edca7e0 commit 9e6a439
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function *run() {
age
createdAt
nums
bools
strings
removed
friends {
name
Expand All @@ -29,7 +31,6 @@ function *run() {
// name
// age
// createdAt
// nums
// removed
// friends {
// name
Expand Down
15 changes: 14 additions & 1 deletion example/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ var UserSchema = new mongoose.Schema({
ref: 'User'
}],
nums: [Number],
removed: Boolean
bools: [Boolean],
strings: [String],
removed: Boolean,

// TODO: support objects
body: {
eye: String,
foot: Number
},

// TODO: support sub-documents
pets: [{
name: String
}]
});

var User = mongoose.model('User', UserSchema);
Expand Down
20 changes: 16 additions & 4 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ function getSchema (models) {

// Array
else if (path.instance === 'Array') {
var type = path.caster.options.ref;
var type;

// Array of refs
if (path.caster.instance === 'ObjectID') {
type = path.caster.options.ref;

return {
type: new GraphQLList(types[type]),
resolve: (modelInstance, params, source, fieldASTs) => {
Expand All @@ -118,9 +120,19 @@ function getSchema (models) {
// Array of primitives
// FIXME: cannot handle array
} else {
return {
// type: new GraphQLList(getField(path.caster))
};
if (path.caster.instance === 'Number') {
return {
type: new GraphQLList(GraphQLInt)
};
} else if (path.caster.instance === 'String') {
return {
type: new GraphQLList(GraphQLString)
};
} else if (path.caster.instance === 'Boolean') {
return {
type: new GraphQLList(GraphQLBoolean)
};
}
}
}

Expand Down

0 comments on commit 9e6a439

Please sign in to comment.