Skip to content

Commit

Permalink
Replaced GQL with NQL
Browse files Browse the repository at this point in the history
refs TryGhost#10105

[ci skip]
  • Loading branch information
kirrg001 committed Dec 9, 2018
1 parent 3d7b4dc commit 20c4805
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
61 changes: 30 additions & 31 deletions core/server/models/plugins/filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var _ = require('lodash'),
gql = require('ghost-gql'),
common = require('../../lib/common'),
filter,
filterUtils;
const _ = require('lodash');
const gql = require('ghost-gql');
const debug = require('ghost-ignition').debug('models:plugins:filter');
const common = require('../../lib/common');

let filter;
let filterUtils;

filterUtils = {
/**
Expand Down Expand Up @@ -175,36 +177,33 @@ filter = function filter(Bookshelf) {
},

/**
* ## Apply Filters
* Method which makes the necessary query builder calls (through knex) for the filters set
* on this model instance
* @param {Object} options
* @returns {Bookshelf.Model}
* @TODO:
*
* - release nql with latest mongo-knex
* - NQL must forward options to mongo-knex
*/
applyDefaultAndCustomFilters: function applyDefaultAndCustomFilters(options) {
var self = this;

// @TODO figure out a better place/way to trigger loading filters
if (!this._filters) {
this.fetchAndCombineFilters(options);
}

if (this._filters) {
if (this.debug) {
gql.json.printStatements(this._filters.statements);
}

this.preProcessFilters(options);

this.query(function (qb) {
gql.knexify(qb, self._filters);
const nql = require('@nexes/nql');

const customFilter = options.filter;
const defaultFilters = this.enforcedFilters(options);
const enforcedFilters = this.enforcedFilters(options);

debug('custom', customFilter);
debug('default', defaultFilters);
debug('enforced', enforcedFilters);

if (customFilter) {
this.query((qb) => {
nql(customFilter, {relations: {tags: {
tableName: 'tags',
type: 'manyToMany',
join_table: 'posts_tags',
join_from: 'post_id',
join_to: 'tag_id'
}}}).querySQL(qb);
});

// Replaces processGQLResult
this.postProcessFilters(options);
}

return this;
}
});

Expand Down
4 changes: 2 additions & 2 deletions core/test/functional/api/v2/content/posts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ describe('Posts', function () {
});
});

it('browse posts with basic filters', function (done) {
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&filter=tag:kitchen-sink,featured:true&include=tags`))
it.only('browse posts with basic filters', function (done) {
request.get(localUtils.API.getApiQuery(`posts/?key=${validKey}&filter=tags.slug:kitchen-sink,featured:true&include=tags`))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)
.expect(200)
Expand Down

0 comments on commit 20c4805

Please sign in to comment.