diff --git a/lib/SchemaBuilder.js b/lib/SchemaBuilder.js index ad2193b..d181b9a 100644 --- a/lib/SchemaBuilder.js +++ b/lib/SchemaBuilder.js @@ -118,7 +118,6 @@ class SchemaBuilder { exclude: modelData.opt.exclude, typeNamePrefix: utils.typeNameForModel(modelData.modelClass), typeCache: this.typeCache, - virtualJsonSchemaProperties: modelData.modelClass.virtualJsonSchemaProperties }); modelData.args = this._argsForModel(modelData); @@ -422,17 +421,17 @@ class SchemaBuilder { if (!this.enableSelectFiltering) { return null; } - const { jsonSchema, virtualJsonSchemaProperties: vProps } = modelClass; - const virtualPropertyFilter = (it) => !(vProps && vProps[it]) const relations = modelClass.getRelations(); - const selects = this._collectSelects(astNode, relations, astRoot.fragments, []).filter(virtualPropertyFilter); + const selects = this._collectSelects(astNode, relations, astRoot.fragments, []); if (selects.length === 0) { return null; } return (builder) => { + const { jsonSchema } = modelClass; + builder.select(selects.map((it) => { const col = modelClass.propertyNameToColumnName(it); diff --git a/lib/jsonSchema.js b/lib/jsonSchema.js index e69ceb1..2307473 100644 --- a/lib/jsonSchema.js +++ b/lib/jsonSchema.js @@ -14,13 +14,11 @@ function jsonSchemaToGraphQLFields(jsonSchema, opt) { typeIndex: 1, typeNamePrefix: '', typeCache: {}, - virtualJsonSchemaProperties: {}, }); const fields = {}; - const augmentedJsonSchemaProperties = Object.assign({}, jsonSchema.properties, ctx.virtualJsonSchemaProperties); - _.forOwn(augmentedJsonSchemaProperties, (propSchema, propName) => { + _.forOwn(jsonSchema.properties, (propSchema, propName) => { if (utils.isExcluded(ctx, propName)) { return; } diff --git a/tests/integration.js b/tests/integration.js index a1fc6c5..670bf11 100644 --- a/tests/integration.js +++ b/tests/integration.js @@ -263,59 +263,6 @@ describe('integration tests', () => { ]); })); - it('`people` field should have all properties defined in the Person model\'s jsonSchema, plus virtual properties', () => graphql(schema, '{ people { age, birthYear, gender, firstName, lastName, parentId, addresses { street, city, zipCode } } }').then((res) => { - console.log(res); - const { data: { people } } = res; - people.sort(sortByFirstName); - - expect(people).to.eql([ - { - age: 73, - birthYear: 1945, - firstName: 'Arnold', - lastName: 'Schwarzenegger', - gender: 'Male', - parentId: 1, - addresses: [{ - street: 'Arnoldlane 12', - city: 'Arnoldova', - zipCode: '123456', - }], - }, - { - age: 98, - birthYear: 1920, - firstName: 'Gustav', - lastName: 'Schwarzenegger', - gender: 'Male', - parentId: null, - addresses: [{ - street: 'Gustavroad 64', - city: 'Gustavia', - zipCode: '654321', - }], - }, - { - age: 45, - birthYear: 1973, - firstName: 'Michael', - lastName: 'Biehn', - gender: 'Male', - parentId: null, - addresses: null, - }, - { - age: 20, - birthYear: 1998, - firstName: 'Some', - lastName: 'Random-Dudette', - gender: 'Female', - parentId: null, - addresses: null, - }, - ]); - })); - it('should work with the meta field `__typename`', () => graphql(schema, '{ reviews { title, __typename } }').then((res) => { expect(res.data.reviews).to.eql([{ __typename: 'Review', diff --git a/tests/setup/models/Person.js b/tests/setup/models/Person.js index a24f4aa..f87c7d8 100644 --- a/tests/setup/models/Person.js +++ b/tests/setup/models/Person.js @@ -14,12 +14,6 @@ class Person extends Model { }; } - static get virtualJsonSchemaProperties() { - return { - birthYear: { type: ['number', 'null'] }, - }; - } - static get jsonSchema() { return { type: 'object', @@ -96,11 +90,7 @@ class Person extends Model { } static get virtualAttributes() { - return ['fullName', 'birthYear']; - } - - birthYear() { - return this.age ? (2018 - this.age) : null; + return ['fullName']; } fullName() {