Fix outgoing headers in /graphql

Fixes #4264
This commit is contained in:
rijkvanzanten
2021-02-24 11:06:55 -05:00
parent 5908822ea9
commit 4cfa64e752
3 changed files with 22 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
import { Router, Response } from 'express';
import { Router } from 'express';
import { graphqlHTTP } from 'express-graphql';
import { GraphQLService } from '../services';
import { respond } from '../middleware/respond';
@@ -27,6 +27,15 @@ router.use(
customResponse.json = customResponse.end = function (payload: Record<string, any>) {
res.locals.payload = payload;
if (customResponse.getHeader('content-type')) {
res.setHeader('Content-Type', customResponse.getHeader('content-type')!);
}
if (customResponse.getHeader('content-length')) {
res.setHeader('content-length', customResponse.getHeader('content-length')!);
}
return next();
} as any;

View File

@@ -153,7 +153,7 @@ export class CollectionsService {
return Array.isArray(collection) ? collections : collections[0];
}
/** @todo, read by query without query support is a bit ironic, isnt it */
/** @todo, read by query without query support is a bit ironic, isn't it */
async readByQuery(): Promise<Collection[]> {
const collectionItemsService = new ItemsService('directus_collections', {
knex: this.knex,

View File

@@ -82,7 +82,17 @@ export class GraphQLService {
};
async getSchema() {
const collectionsInSystem = await this.collectionsService.readByQuery();
let collectionsInSystem: Collection[] = [];
// Collections service will throw an error if you don't have access to any collection.
// We still want GraphQL / GraphiQL to function though, even if you don't have access to `items`
// (you could still have access to auth/server/etc)
try {
collectionsInSystem = await this.collectionsService.readByQuery();
} catch {
collectionsInSystem = [];
}
const fieldsInSystem = await this.fieldsService.readAll();
const relationsInSystem = (await this.relationsService.readByQuery({})) as Relation[];