mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user