@kubun/graphql 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/schema.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- import { AttachmentID } from '@kubun/id';
1
+ import { AttachmentID, DocumentModelID } from '@kubun/id';
2
2
  import { type ArrayModel, type DocumentData, type DocumentModel, type DocumentModelSchema, type DocumentModelsRecord, type ObjectModel, type ReferencesRecordModel, type ScalarModel, type StringCustomModel, type StringEnumModel, type StringFormatModel, type StringModel, type TypeModel } from '@kubun/protocol';
3
3
  import { GraphQLEnumType, type GraphQLFieldConfig, type GraphQLFieldConfigMap, GraphQLInputObjectType, type GraphQLInputType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, type GraphQLOutputType, type GraphQLScalarType, GraphQLSchema } from 'graphql';
4
4
  import { type Connection, type ConnectionArguments } from 'graphql-relay';
5
+ export declare function toDocumentModelID(id: DocumentModelID | string): DocumentModelID;
6
+ export declare function getGlobalID(id: DocumentModelID | string, globalID: DocumentModelID | string): DocumentModelID;
5
7
  export declare function toList(type: GraphQLInputType): GraphQLList<GraphQLNonNull<GraphQLInputType>>;
8
+ export declare function toOuputList(type: GraphQLOutputType): GraphQLList<GraphQLNonNull<GraphQLOutputType>>;
6
9
  export declare const PatchOperation: GraphQLInputObjectType;
7
10
  export type DocumentType = {
8
11
  id: string;
@@ -30,13 +33,16 @@ export type SchemaBuilderParams = {
30
33
  export declare class SchemaBuilder<Document extends DocumentType = DocumentType, Context extends ContextType = ContextType, Definitions extends SharedDefinitions<Document, Context> = SharedDefinitions<Document, Context>> {
31
34
  _aliases: Record<string, string>;
32
35
  _definitions: Definitions | undefined;
36
+ _implemented: Record<string, Array<string>>;
37
+ _inputObjects: Record<string, GraphQLInputObjectType>;
38
+ _mutations: Record<string, GraphQLFieldConfig<unknown, Context>>;
39
+ _nodeModelIDs: Array<string>;
33
40
  _record: DocumentModelsRecord;
34
41
  _references: ReferencesRecordModel;
35
42
  _relationsTo: Record<string, Record<string, string>>;
36
43
  _types: Record<string, GraphQLOutputType>;
37
- _inputObjects: Record<string, GraphQLInputObjectType>;
38
- _mutations: Record<string, GraphQLFieldConfig<unknown, Context>>;
39
44
  constructor(params: SchemaBuilderParams);
45
+ getModelIDs(id: string | null): Array<string>;
40
46
  getViewer(ctx: Context): string | null;
41
47
  loadDocument(id: string, ctx: Context): Promise<Document | null>;
42
48
  resolveConnection(model: string | null, args: ConnectionArguments, ctx: Context): Promise<Connection<Document>>;
@@ -48,7 +54,7 @@ export declare class SchemaBuilder<Document extends DocumentType = DocumentType,
48
54
  _getReferenceSchema(id: string): TypeModel;
49
55
  _getReferenceInput(path: string, isPartial: boolean, parentName?: string): GraphQLInputType;
50
56
  _buildSharedDefinitions(): Definitions;
51
- _buildDocument(id: string): GraphQLObjectType<Document, Context>;
57
+ _buildDocument(id: string): GraphQLObjectType<Document, Context> | GraphQLInterfaceType;
52
58
  _buildDocumentInput(id: string, model: DocumentModel): void;
53
59
  _buildReferenceFilterInput(path: string, parentName?: string): GraphQLInputType;
54
60
  _buildReferenceOrderByInput(path: string, parentName?: string): GraphQLInputType | null;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyC,MAAM,WAAW,CAAA;AAC/E,OAAO,EACL,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAEhB,KAAK,qBAAqB,EAC1B,KAAK,WAAW,EAEhB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAEhB,KAAK,SAAS,EACf,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAEL,eAAe,EAEf,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAI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Ae;IAQxC,kBAAkB,CAAC,MAAM,EAAE,iBAAiB;CAO7C"}
package/lib/schema.js CHANGED
@@ -25,10 +25,27 @@ function getReferenceID(path) {
25
25
  function isList(type) {
26
26
  return isListType(type) || isNonNullType(type) && isListType(type.ofType);
27
27
  }
28
+ function collectAllModelIDs(collected, record, interfaceID) {
29
+ const { isInterface, implementedBy } = record[interfaceID];
30
+ for (const id of implementedBy){
31
+ if (isInterface) {
32
+ collectAllModelIDs(collected, record, id);
33
+ } else {
34
+ collected.add(id);
35
+ }
36
+ }
37
+ }
38
+ export function toDocumentModelID(id) {
39
+ return id instanceof DocumentModelID ? id : DocumentModelID.fromString(id);
40
+ }
41
+ export function getGlobalID(id, globalID) {
42
+ const docModelID = toDocumentModelID(id);
43
+ return docModelID.isLocal ? docModelID.toGlobal(toDocumentModelID(globalID)) : docModelID;
44
+ }
28
45
  export function toList(type) {
29
46
  return new GraphQLList(new GraphQLNonNull(type));
30
47
  }
31
- function toOuputList(type) {
48
+ export function toOuputList(type) {
32
49
  return new GraphQLList(new GraphQLNonNull(type));
33
50
  }
34
51
  function createEnumValueFilterInput(type) {
@@ -197,34 +214,60 @@ export class SchemaBuilder {
197
214
  // Mapping of model or references IDs to their GraphQL object names
198
215
  _aliases;
199
216
  _definitions;
217
+ _implemented = {};
218
+ _inputObjects = {
219
+ ...VALUE_FILTER_INPUTS,
220
+ PatchOperation
221
+ };
222
+ _mutations = {};
223
+ _nodeModelIDs;
200
224
  _record;
201
225
  _references = {};
202
226
  _relationsTo = {};
203
227
  _types = {
204
228
  OrderByDirection
205
229
  };
206
- _inputObjects = {
207
- ...VALUE_FILTER_INPUTS,
208
- PatchOperation
209
- };
210
- _mutations = {};
211
230
  constructor(params){
212
231
  this._aliases = params.aliases ?? {};
213
232
  this._record = params.record;
214
- for (const [id, model] of Object.entries(params.record)){
215
- const modelID = DocumentModelID.fromString(id);
233
+ const referencedInterfaces = {};
234
+ for (const [modelIDstring, model] of Object.entries(params.record)){
235
+ const modelID = DocumentModelID.fromString(modelIDstring);
216
236
  Object.assign(this._references, model.schema.$defs ?? {});
237
+ // Extract interfaces
238
+ for (const iid of model.interfaces){
239
+ const interfaceID = getGlobalID(iid, modelID).toString();
240
+ referencedInterfaces[interfaceID] ??= {
241
+ isInterface: model.behavior === 'interface',
242
+ implementedBy: new Set()
243
+ };
244
+ referencedInterfaces[interfaceID].implementedBy.add(modelIDstring);
245
+ }
217
246
  // Extract inverse relations
218
247
  for (const [fieldName, meta] of Object.entries(model.fieldsMeta)){
219
248
  if (meta.relationModel != null) {
220
- const relationModelID = DocumentModelID.fromString(meta.relationModel);
221
- const globalID = relationModelID.isLocal ? relationModelID.toGlobal(modelID) : relationModelID;
222
- const relationID = globalID.toString();
249
+ const relationID = getGlobalID(meta.relationModel, modelID).toString();
223
250
  this._relationsTo[relationID] ??= {};
224
- this._relationsTo[relationID][fieldName] = id;
251
+ this._relationsTo[relationID][fieldName] = modelIDstring;
225
252
  }
226
253
  }
227
254
  }
255
+ // Map interface IDs to all the models implementing them
256
+ const nodeModelIDs = new Set();
257
+ for (const id of Object.keys(referencedInterfaces)){
258
+ const implementedBy = new Set();
259
+ collectAllModelIDs(implementedBy, referencedInterfaces, id);
260
+ this._implemented[id] = Array.from(implementedBy);
261
+ for (const modelID of implementedBy){
262
+ nodeModelIDs.add(modelID);
263
+ }
264
+ }
265
+ this._nodeModelIDs = Array.from(nodeModelIDs);
266
+ }
267
+ getModelIDs(id) {
268
+ return id === null ? this._nodeModelIDs : this._implemented[id] ?? [
269
+ id
270
+ ];
228
271
  }
229
272
  getViewer(ctx) {
230
273
  throw new Error('Must be implemented');
@@ -488,16 +531,21 @@ export class SchemaBuilder {
488
531
  }
489
532
  const definitions = this._getDefinitions();
490
533
  this._aliases[id] ??= pascalCase(model.name);
491
- const nodeType = new GraphQLObjectType({
534
+ const config = {
492
535
  name: this._aliases[id],
493
- interfaces: [
494
- definitions.documentInterface,
495
- definitions.nodeInterface
496
- ],
497
- fields: ()=>{
498
- return this._buildObjectFields(id, model.schema, model);
499
- }
500
- });
536
+ interfaces: ()=>{
537
+ return [
538
+ definitions.documentInterface,
539
+ definitions.nodeInterface
540
+ ].concat(model.interfaces.map((interfaceID)=>{
541
+ return this._types[getGlobalID(interfaceID, id).toString()];
542
+ }));
543
+ },
544
+ fields: ()=>this._buildObjectFields(id, model.schema, model),
545
+ isTypeOf: (doc)=>DocumentID.fromString(doc.id).model.toString() === id
546
+ };
547
+ const isInterface = model.behavior === 'interface';
548
+ const nodeType = isInterface ? new GraphQLInterfaceType(config) : new GraphQLObjectType(config);
501
549
  const { connectionType, edgeType } = connectionDefinitions({
502
550
  nodeType
503
551
  });
@@ -755,40 +803,43 @@ export class SchemaBuilder {
755
803
  fields[key] = {
756
804
  type: required.includes(key) ? new GraphQLNonNull(type) : type
757
805
  };
758
- if (model != null) {
759
- fields[key].resolve = (doc)=>doc.data?.[key];
760
- const relationModel = model.fieldsMeta[key]?.relationModel;
761
- if (typeof relationModel !== 'undefined') {
762
- let relationModelID;
763
- let relationType;
764
- if (relationModel === null) {
765
- relationModelID = null;
766
- relationType = definitions.documentInterface;
767
- } else {
768
- const relationID = DocumentModelID.fromString(relationModel);
769
- relationModelID = (relationID.isLocal ? relationID.toGlobal(DocumentModelID.fromString(id)) : relationID).toString();
770
- relationType = this._buildDocument(relationModelID);
771
- }
772
- if (isList(type)) {
773
- // TODO: add suport for filters?
774
- fields[`_${key}_documents`] = {
775
- type: new GraphQLNonNull(toOuputList(relationType)),
776
- resolve: async (doc, _args, ctx)=>{
777
- const relationIDs = doc.data?.[key] ?? [];
778
- return relationIDs.length ? await this.resolveList(relationModelID, relationIDs, ctx) : [];
779
- }
780
- };
781
- } else {
782
- fields[`_${key}_document`] = {
783
- type: relationType,
784
- resolve: async (doc, _args, ctx)=>{
785
- const relationID = doc.data?.[key];
786
- return relationID ? await this.loadDocument(relationID, ctx) : null;
787
- }
788
- };
789
- }
806
+ if (model == null) {
807
+ continue;
808
+ }
809
+ fields[key].resolve = (doc)=>doc.data?.[key];
810
+ const relationModel = model.fieldsMeta[key]?.relationModel;
811
+ if (typeof relationModel !== 'undefined') {
812
+ let relationModelID;
813
+ let relationType;
814
+ if (relationModel === null) {
815
+ relationModelID = null;
816
+ relationType = definitions.documentInterface;
817
+ } else {
818
+ relationModelID = getGlobalID(relationModel, id).toString();
819
+ relationType = this._buildDocument(relationModelID);
820
+ }
821
+ if (isList(type)) {
822
+ // TODO: add suport for filters?
823
+ fields[`_${key}_documents`] = {
824
+ type: new GraphQLNonNull(toOuputList(relationType)),
825
+ resolve: async (doc, _args, ctx)=>{
826
+ const relationIDs = doc.data?.[key] ?? [];
827
+ return relationIDs.length ? await this.resolveList(relationModelID, relationIDs, ctx) : [];
828
+ }
829
+ };
830
+ } else {
831
+ fields[`_${key}_document`] = {
832
+ type: relationType,
833
+ resolve: async (doc, _args, ctx)=>{
834
+ const relationID = doc.data?.[key];
835
+ return relationID ? await this.loadDocument(relationID, ctx) : null;
836
+ }
837
+ };
790
838
  }
791
- for (const [fieldName, relationID] of Object.entries(this._relationsTo[id] ?? {})){
839
+ }
840
+ for (const iid of model.interfaces ?? []){
841
+ const interfaceID = getGlobalID(iid, id).toString();
842
+ for (const [fieldName, relationID] of Object.entries(this._relationsTo[interfaceID] ?? {})){
792
843
  const relationName = this._aliases[relationID];
793
844
  fields[`_${fieldName}_of_${relationName}_list`] = {
794
845
  type: new GraphQLNonNull(this._types[`${relationID}-connection`])
@@ -798,6 +849,15 @@ export class SchemaBuilder {
798
849
  };
799
850
  }
800
851
  }
852
+ for (const [fieldName, relationID] of Object.entries(this._relationsTo[id] ?? {})){
853
+ const relationName = this._aliases[relationID];
854
+ fields[`_${fieldName}_of_${relationName}_list`] = {
855
+ type: new GraphQLNonNull(this._types[`${relationID}-connection`])
856
+ };
857
+ fields[`_${fieldName}_of_${relationName}_count`] = {
858
+ type: new GraphQLNonNull(GraphQLInt)
859
+ };
860
+ }
801
861
  }
802
862
  return fields;
803
863
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/graphql",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "license": "see LICENSE.md",
5
5
  "keywords": [],
6
6
  "type": "module",