Skip to content

Commit

Permalink
closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Jul 11, 2017
1 parent 4a5efc6 commit 06f921f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/SchemaBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,13 @@ class SchemaBuilder {
}

return (builder) => {
builder.select(selects);
builder.select(selects.map(it => {
if (modelClass.jsonSchema.properties[it]) {
return `${builder.tableRefFor(modelClass)}.${it}`;
} else {
return it;
}
}));
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "objection-graphql",
"version": "0.2.0",
"version": "0.2.1",
"description": "Automatically generates GraphQL schema for objection.js models",
"main": "objection-graphql.js",
"scripts": {
Expand Down
14 changes: 13 additions & 1 deletion tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,16 @@ describe('integration tests', () => {
});

it('should be able to fetch nested relations', () => {
return graphql(schema, '{ movies { name, actors { firstName, movies { name } }, reviews { title, reviewer { firstName } } } }').then(res => {
return graphql(schema, '{ movies { id, name, actors { id, firstName, movies { name } }, reviews { id, title, reviewer { id, firstName } } } }').then(res => {
const terminator = _.find(res.data.movies, {name: 'The terminator'});

expect(terminator).to.eql({
id: 1,
name: 'The terminator',
actors: [{
id: 4,
firstName: 'Arnold',

movies: [{
name: 'The terminator'
}, {
Expand All @@ -391,19 +394,28 @@ describe('integration tests', () => {
name: 'Predator'
}]
}, {
id: 2,
firstName: 'Michael',

movies: [{
name: 'The terminator'
}]
}],

reviews: [{
id: 1,
title: 'Great movie',

reviewer: {
id: 3,
firstName: 'Some'
}
}, {
id: 2,
title: 'Changed my mind',

reviewer: {
id: 3,
firstName: 'Some'
}
}]
Expand Down
1 change: 1 addition & 0 deletions tests/setup/IntegrationTestSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class IntegrationTestSession {
});
}).then(() => {
return knex.schema.createTable('Person_Movie', (table) => {
table.increments('id').primary();
table.integer('movieId')
.references('id')
.inTable('Movie')
Expand Down

0 comments on commit 06f921f

Please sign in to comment.