Update koa-graphql, add custom responses

This commit is contained in:
Aurélien Georget 2016-03-11 14:11:05 +01:00
parent f4d2ec43a9
commit 61f492c6cd
4 changed files with 14 additions and 1 deletions

View File

@ -8,6 +8,7 @@ module.exports = {
_config: true,
_api: true,
_hooks: true,
responses: true,
responseTime: true,
bodyParser: true,
session: true,

View File

@ -61,6 +61,7 @@ module.exports = {
keyForAttribute: 'dash-case',
pluralizeType: false,
included: true,
ignoreRelationshipData: false,
typeForAttribute: function (currentType) {
if (strapi.models.hasOwnProperty(type)) {
return _.first(_.reject(_.map(strapi.models[type].associations, function (relation) {

View File

@ -13,6 +13,7 @@ const _ = require('lodash');
// Local utilities.
const regex = require('../../../../util/regex');
const JSONAPI = require('../jsonapi')();
const responsesPolicy = require('../responses/policies/responses');
/**
* Router hook
@ -63,6 +64,11 @@ module.exports = function (strapi) {
let action;
let policies = [];
// Add the `responsesPolicy` to the list of policies.
if (strapi.config.responses) {
strapi.policies.responsesPolicy = responsesPolicy;
}
// Initialize the router.
if (!strapi.router) {
strapi.router = strapi.middlewares.router({
@ -90,6 +96,11 @@ module.exports = function (strapi) {
// Add the `globalPolicy`.
policies.push(globalPolicy(endpoint, value, route));
// Add the `responsesPolicy`.
if (strapi.config.responses) {
policies.push(responsesPolicy);
}
// Enabled JSON API support
if ((_.isPlainObject(strapi.config.jsonapi) && strapi.config.jsonapi.enabled === true) || (_.isBoolean(strapi.config.jsonapi) && strapi.config.jsonapi === true)) {
policies.push(JSONAPI.parse(strapi));

View File

@ -42,7 +42,7 @@
"koa-compose": "~2.3.0",
"koa-cors": "~0.0.16",
"koa-favicon": "~1.2.0",
"koa-graphql": "^0.4.4",
"koa-graphql": "^0.4.5",
"koa-gzip": "~0.1.0",
"koa-i18n": "~1.2.0",
"koa-ip": "~0.1.0",