From 06f921fd37ede59e0a82295addabc806a28622e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Koskim=C3=A4ki?= Date: Tue, 11 Jul 2017 13:39:10 +0300 Subject: [PATCH] closes #8 --- lib/SchemaBuilder.js | 8 +++++++- package.json | 2 +- tests/integration.js | 14 +++++++++++++- tests/setup/IntegrationTestSession.js | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/SchemaBuilder.js b/lib/SchemaBuilder.js index b5d1ddb..3f96590 100644 --- a/lib/SchemaBuilder.js +++ b/lib/SchemaBuilder.js @@ -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; + } + })); }; } } diff --git a/package.json b/package.json index 2fff017..bbddef5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tests/integration.js b/tests/integration.js index e30a8a6..83f1dee 100644 --- a/tests/integration.js +++ b/tests/integration.js @@ -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' }, { @@ -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' } }] diff --git a/tests/setup/IntegrationTestSession.js b/tests/setup/IntegrationTestSession.js index 54e826f..5e01763 100644 --- a/tests/setup/IntegrationTestSession.js +++ b/tests/setup/IntegrationTestSession.js @@ -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')