Skip to content

Commit

Permalink
Revert "Merge pull request #55 from timhuff/original"
Browse files Browse the repository at this point in the history
This reverts commit fd2f42b, reversing
changes made to 6898d68.
  • Loading branch information
timhuff committed Jun 18, 2018
1 parent 7590e61 commit 5f66ce1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 71 deletions.
7 changes: 3 additions & 4 deletions lib/SchemaBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions lib/jsonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
53 changes: 0 additions & 53 deletions tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 1 addition & 11 deletions tests/setup/models/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ class Person extends Model {
};
}

static get virtualJsonSchemaProperties() {
return {
birthYear: { type: ['number', 'null'] },
};
}

static get jsonSchema() {
return {
type: 'object',
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5f66ce1

Please sign in to comment.