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:
Rijk van Zanten
2021-03-30 17:06:35 -04:00
committed by GitHub
parent fb91fd57e0
commit f90c31b798
37 changed files with 1637 additions and 769 deletions

View File

@@ -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;
}
}