mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
GraphQL 2.0 (#4625)
* Start on GraphQL "2.0", add methodnotallowed exceptoin * Fix relative file pointer in peer dep * [WIP] Add pre-filtered schema to SchemaOverview * Use root schema as is, add reduce-schema util * Use reduceSchema in the wild * Base schema on local reduced schema * Remove todo * Use graphql-compose to build out schema * Start restructuring resolvers * Add create mutation * Return boolean true for empty create mutation selections * Add update mutation * Add delete mutation * Add system/items scoping * Fix merge conflicts for real now * Use system services, rename ids->keys * Start on docs on mutations * Updates to match main * Add fetch-by-id * Add one/many resolvers for mutations * Check system collection rows for singleton * Fix resolver extraction for single read * Share delete return type * Add comments * Use collection root name for readable type * Add specs endpoint for GraphQL SDL * Update docs * Add note on SDL spec * Fix delete single example * Remove package-lock * Fix collection read scoping in non-read
This commit is contained in:
@@ -23,6 +23,7 @@ import openapi from '@directus/specs';
|
||||
import { Knex } from 'knex';
|
||||
import database from '../database';
|
||||
import { getRelationType } from '../utils/get-relation-type';
|
||||
import { GraphQLService } from './graphql';
|
||||
|
||||
export class SpecificationService {
|
||||
accountability: Accountability | null;
|
||||
@@ -33,7 +34,8 @@ export class SpecificationService {
|
||||
collectionsService: CollectionsService;
|
||||
relationsService: RelationsService;
|
||||
|
||||
oas: OASService;
|
||||
oas: OASSpecsService;
|
||||
graphql: GraphQLSpecsService;
|
||||
|
||||
constructor(options: AbstractServiceOptions) {
|
||||
this.accountability = options.accountability || null;
|
||||
@@ -44,22 +46,21 @@ export class SpecificationService {
|
||||
this.collectionsService = new CollectionsService(options);
|
||||
this.relationsService = new RelationsService(options);
|
||||
|
||||
this.oas = new OASService(
|
||||
{ knex: this.knex, accountability: this.accountability, schema: this.schema },
|
||||
{
|
||||
fieldsService: this.fieldsService,
|
||||
collectionsService: this.collectionsService,
|
||||
relationsService: this.relationsService,
|
||||
}
|
||||
);
|
||||
this.oas = new OASSpecsService(options, {
|
||||
fieldsService: this.fieldsService,
|
||||
collectionsService: this.collectionsService,
|
||||
relationsService: this.relationsService,
|
||||
});
|
||||
|
||||
this.graphql = new GraphQLSpecsService(options);
|
||||
}
|
||||
}
|
||||
|
||||
interface SpecificationSubService {
|
||||
generate: () => Promise<any>;
|
||||
generate: (_?: any) => Promise<any>;
|
||||
}
|
||||
|
||||
class OASService implements SpecificationSubService {
|
||||
class OASSpecsService implements SpecificationSubService {
|
||||
accountability: Accountability | null;
|
||||
knex: Knex;
|
||||
schema: SchemaOverview;
|
||||
@@ -531,3 +532,27 @@ class OASService implements SpecificationSubService {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
class GraphQLSpecsService implements SpecificationSubService {
|
||||
accountability: Accountability | null;
|
||||
knex: Knex;
|
||||
schema: SchemaOverview;
|
||||
|
||||
items: GraphQLService;
|
||||
system: GraphQLService;
|
||||
|
||||
constructor(options: AbstractServiceOptions) {
|
||||
this.accountability = options.accountability || null;
|
||||
this.knex = options.knex || database;
|
||||
this.schema = options.schema;
|
||||
|
||||
this.items = new GraphQLService({ ...options, scope: 'items' });
|
||||
this.system = new GraphQLService({ ...options, scope: 'system' });
|
||||
}
|
||||
|
||||
async generate(scope: 'items' | 'system') {
|
||||
if (scope === 'items') return this.items.getSchema('sdl');
|
||||
if (scope === 'system') return this.system.getSchema('sdl');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user