@kubun/graphql 0.3.4 → 0.3.6
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/context.d.ts +44 -0
- package/lib/context.d.ts.map +1 -0
- package/lib/context.js +120 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/schema.d.ts +4 -38
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +19 -10
- package/lib/types.d.ts +11 -0
- package/lib/types.d.ts.map +1 -1
- package/package.json +7 -5
package/lib/context.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { KubunDB } from '@kubun/db';
|
|
2
|
+
import type { DocumentData, DocumentNode } from '@kubun/protocol';
|
|
3
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
4
|
+
import type { Connection, Edge } from 'graphql-relay';
|
|
5
|
+
import type { AllConnectionArguments, UpdateMutationInput } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Query functions requiring server implementation
|
|
8
|
+
*/
|
|
9
|
+
export type QueryContext = {
|
|
10
|
+
getViewer(): string | null;
|
|
11
|
+
loadDocument(id: string): Promise<DocumentNode | null>;
|
|
12
|
+
resolveConnection(modelIDs: Array<string>, args: AllConnectionArguments): Promise<Connection<DocumentNode>>;
|
|
13
|
+
resolveList(modelIDs: Array<string>, ids: Array<string>): Promise<Array<DocumentNode>>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Subscription functions requiring server implementation
|
|
17
|
+
*/
|
|
18
|
+
export type SubscriptionContext = {
|
|
19
|
+
subscribeToDocumentCreated(modelIDs: Array<string>): AsyncGenerator<DocumentNode>;
|
|
20
|
+
subscribeToDocumentChanged(id: string): AsyncGenerator<DocumentNode>;
|
|
21
|
+
subscribeToDocumentRemoved(): AsyncGenerator<string>;
|
|
22
|
+
subscribeToDocumentEdgeAdded(modelIDs: Array<string>, hasRelation: (data: DocumentData) => boolean): AsyncGenerator<Edge<DocumentNode>>;
|
|
23
|
+
subscribeToDocumentEdgeRemoved(modelIDs: Array<string>, hasRelation: (data: DocumentData) => boolean): AsyncGenerator<string>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Query and subscription functions requiring server implementation
|
|
27
|
+
*/
|
|
28
|
+
export type ReadOnlyContext = QueryContext & SubscriptionContext;
|
|
29
|
+
export type ReadContextParams = {
|
|
30
|
+
db: KubunDB;
|
|
31
|
+
viewerDID: string;
|
|
32
|
+
};
|
|
33
|
+
export declare function createReadContext(params: ReadContextParams): ReadOnlyContext;
|
|
34
|
+
/**
|
|
35
|
+
* Mutation function requiring client implementation
|
|
36
|
+
*/
|
|
37
|
+
export type MutationContext = {
|
|
38
|
+
executeCreateMutation(modelID: string, data: DocumentData, info: GraphQLResolveInfo): Promise<DocumentNode>;
|
|
39
|
+
executeSetMutation(modelID: string, unique: Uint8Array, data: DocumentData, info: GraphQLResolveInfo): Promise<DocumentNode>;
|
|
40
|
+
executeUpdateMutation(input: UpdateMutationInput, info: GraphQLResolveInfo): Promise<DocumentNode>;
|
|
41
|
+
executeRemoveMutation(id: string, info: GraphQLResolveInfo): Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
export type Context = ReadOnlyContext & MutationContext;
|
|
44
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,OAAO,EAAE,MAAM,WAAW,CAAA;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAuB,IAAI,EAAE,MAAM,eAAe,CAAA;AAE1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAmB,EAA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AAE,MAAM,CAAA;CAClB,CAAA;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CA4I5E;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB,CACnB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,YAAY,CAAC,CAAA;IACxB,kBAAkB,CAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,YAAY,EAClB,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,YAAY,CAAC,CAAA;IACxB,qBAAqB,CAAC,KAAK,EAAE,mBAAmB,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IAClG,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3E,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,eAAe,GAAG,eAAe,CAAA"}
|
package/lib/context.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { defer } from '@enkaku/async';
|
|
2
|
+
import { DocumentID } from '@kubun/id';
|
|
3
|
+
export function createReadContext(params) {
|
|
4
|
+
const { db, viewerDID } = params;
|
|
5
|
+
function createEventGenerator(filter, transform) {
|
|
6
|
+
let isDone = false;
|
|
7
|
+
let pending = null;
|
|
8
|
+
const queue = [];
|
|
9
|
+
const stop = db.events.on('document:saved', (event)=>{
|
|
10
|
+
if (filter(event)) {
|
|
11
|
+
const toPush = transform(event);
|
|
12
|
+
if (pending == null) {
|
|
13
|
+
queue.push(toPush);
|
|
14
|
+
} else {
|
|
15
|
+
pending.resolve(toPush);
|
|
16
|
+
pending = null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const setDone = ()=>{
|
|
21
|
+
stop();
|
|
22
|
+
isDone = true;
|
|
23
|
+
return Promise.resolve({
|
|
24
|
+
done: true,
|
|
25
|
+
value: undefined
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
[Symbol.asyncIterator] () {
|
|
30
|
+
return this;
|
|
31
|
+
},
|
|
32
|
+
next: ()=>{
|
|
33
|
+
if (isDone) {
|
|
34
|
+
return Promise.resolve({
|
|
35
|
+
done: true,
|
|
36
|
+
value: undefined
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const value = queue.shift();
|
|
40
|
+
if (value != null) {
|
|
41
|
+
return Promise.resolve({
|
|
42
|
+
value,
|
|
43
|
+
done: false
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
pending = defer();
|
|
47
|
+
return pending.promise.then((value)=>({
|
|
48
|
+
value,
|
|
49
|
+
done: false
|
|
50
|
+
}));
|
|
51
|
+
},
|
|
52
|
+
return: setDone,
|
|
53
|
+
throw: setDone
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
getViewer () {
|
|
58
|
+
return viewerDID;
|
|
59
|
+
},
|
|
60
|
+
async loadDocument (id) {
|
|
61
|
+
return await db.getDocument(DocumentID.fromString(id));
|
|
62
|
+
},
|
|
63
|
+
async resolveConnection (modelIDs, args) {
|
|
64
|
+
// TODO: access control filtering
|
|
65
|
+
const { entries, hasMore } = await db.queryDocuments({
|
|
66
|
+
...args,
|
|
67
|
+
modelIDs
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
edges: entries.map((e)=>({
|
|
71
|
+
cursor: e.cursor,
|
|
72
|
+
node: e.document
|
|
73
|
+
})),
|
|
74
|
+
pageInfo: {
|
|
75
|
+
hasNextPage: args.first ? hasMore : false,
|
|
76
|
+
hasPreviousPage: args.first ? false : hasMore,
|
|
77
|
+
endCursor: entries.at(-1)?.cursor ?? null,
|
|
78
|
+
startCursor: entries.at(0)?.cursor ?? null
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
async resolveList (modelIDs, docIDs) {
|
|
83
|
+
return await db.listDocuments({
|
|
84
|
+
modelIDs,
|
|
85
|
+
docIDs
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
subscribeToDocumentCreated (modelIDs) {
|
|
89
|
+
return createEventGenerator((event)=>event.type === 'create' && modelIDs.includes(event.document.model), (event)=>event.document);
|
|
90
|
+
},
|
|
91
|
+
subscribeToDocumentChanged (id) {
|
|
92
|
+
return createEventGenerator((event)=>{
|
|
93
|
+
return event.type === 'update' && event.document.id === id && event.document.data !== null;
|
|
94
|
+
}, (event)=>event.document);
|
|
95
|
+
},
|
|
96
|
+
subscribeToDocumentRemoved () {
|
|
97
|
+
return createEventGenerator((event)=>event.type === 'update' && event.document.data === null, (event)=>event.document.id);
|
|
98
|
+
},
|
|
99
|
+
subscribeToDocumentEdgeAdded (modelIDs, hasRelation) {
|
|
100
|
+
return createEventGenerator((event)=>{
|
|
101
|
+
return(// document has data
|
|
102
|
+
event.document.data !== null && // document model is one of the target models
|
|
103
|
+
modelIDs.includes(event.document.model) && // relation field targets the expected document
|
|
104
|
+
hasRelation(event.document.data) && // new document or new relation to document
|
|
105
|
+
(event.type === 'create' || event.previous.data !== null && hasRelation(event.previous.data)));
|
|
106
|
+
}, (event)=>({
|
|
107
|
+
cursor: event.getCursor(),
|
|
108
|
+
node: event.document
|
|
109
|
+
}));
|
|
110
|
+
},
|
|
111
|
+
subscribeToDocumentEdgeRemoved (modelIDs, hasRelation) {
|
|
112
|
+
return createEventGenerator((event)=>{
|
|
113
|
+
return event.type === 'update' && // document model is one of the target models
|
|
114
|
+
modelIDs.includes(event.document.model) && // relation existed in previous version
|
|
115
|
+
event.previous.data !== null && hasRelation(event.previous.data) && // relation is removed
|
|
116
|
+
(event.document.data === null || !hasRelation(event.document.data));
|
|
117
|
+
}, (event)=>event.document.id);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
export type { Context, MutationContext, QueryContext, ReadContextParams, ReadOnlyContext, SubscriptionContext, } from './context.js';
|
|
2
|
+
export { createReadContext } from './context.js';
|
|
1
3
|
export { GraphQLAttachmentID, GraphQLDocID } from './identifiers.js';
|
|
2
4
|
export * as scalars from './scalars.js';
|
|
3
|
-
export type {
|
|
5
|
+
export type { SchemaBuilderParams, SharedDefinitions, } from './schema.js';
|
|
4
6
|
export { SchemaBuilder, createSchema } from './schema.js';
|
|
5
7
|
export type * from './types.js';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,mBAAmB,GACpB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,YAAY,EACV,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACzD,mBAAmB,YAAY,CAAA"}
|
package/lib/index.js
CHANGED
package/lib/schema.d.ts
CHANGED
|
@@ -1,46 +1,12 @@
|
|
|
1
1
|
import { AttachmentID, DocumentModelID } from '@kubun/id';
|
|
2
|
-
import type { ArrayModel, DocumentData,
|
|
3
|
-
import { GraphQLEnumType, type GraphQLFieldConfig, type GraphQLFieldConfigMap, GraphQLInputObjectType, type GraphQLInputType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, type GraphQLOutputType, type
|
|
4
|
-
import
|
|
5
|
-
import type { PatchOperation as PatchOperationType } from './types.js';
|
|
2
|
+
import type { ArrayModel, DocumentData, DocumentModel, DocumentModelSchema, DocumentModelsRecord, DocumentNode, ObjectModel, ReferencesRecordModel, ScalarModel, StringCustomModel, StringEnumModel, StringFormatModel, StringModel, TypeModel } from '@kubun/protocol';
|
|
3
|
+
import { GraphQLEnumType, type GraphQLFieldConfig, type GraphQLFieldConfigMap, GraphQLInputObjectType, type GraphQLInputType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, type GraphQLOutputType, type GraphQLScalarType, GraphQLSchema } from 'graphql';
|
|
4
|
+
import type { Context } from './context.js';
|
|
6
5
|
export declare function toDocumentModelID(id: DocumentModelID | string): DocumentModelID;
|
|
7
6
|
export declare function getGlobalID(id: DocumentModelID | string, globalID: DocumentModelID | string): DocumentModelID;
|
|
8
7
|
export declare function toList(type: GraphQLInputType): GraphQLList<GraphQLNonNull<GraphQLInputType>>;
|
|
9
8
|
export declare function toOuputList(type: GraphQLOutputType): GraphQLList<GraphQLNonNull<GraphQLOutputType>>;
|
|
10
9
|
export declare const PatchOperation: GraphQLInputObjectType;
|
|
11
|
-
type AllConnectionArguments = ConnectionArguments & {
|
|
12
|
-
filter?: DocumentFilter;
|
|
13
|
-
orderBy?: DocumentOrderBy;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Query and subscription functions requiring server implementation
|
|
17
|
-
*/
|
|
18
|
-
export type ReadContext = {
|
|
19
|
-
getViewer(): string | null;
|
|
20
|
-
loadDocument(id: string): Promise<DocumentNode | null>;
|
|
21
|
-
resolveConnection(modelIDs: Array<string>, args: AllConnectionArguments): Promise<Connection<DocumentNode>>;
|
|
22
|
-
resolveList(modelIDs: Array<string>, ids: Array<string>): Promise<Array<DocumentNode>>;
|
|
23
|
-
subscribeToDocumentCreated(modelIDs: Array<string>): AsyncGenerator<DocumentNode>;
|
|
24
|
-
subscribeToDocumentChanged(id: string): AsyncGenerator<DocumentNode>;
|
|
25
|
-
subscribeToDocumentRemoved(): AsyncGenerator<string>;
|
|
26
|
-
subscribeToDocumentEdgeAdded(modelIDs: Array<string>, hasRelation: (data: DocumentData) => boolean): AsyncGenerator<Edge<DocumentNode>>;
|
|
27
|
-
subscribeToDocumentEdgeRemoved(modelIDs: Array<string>, hasRelation: (data: DocumentData) => boolean): AsyncGenerator<string>;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Mutation function requiring client implementation
|
|
31
|
-
*/
|
|
32
|
-
export type WriteContext = {
|
|
33
|
-
executeCreateMutation(modelID: string, data: DocumentData, info: GraphQLResolveInfo): Promise<DocumentNode>;
|
|
34
|
-
executeSetMutation(modelID: string, unique: Uint8Array, data: DocumentData, info: GraphQLResolveInfo): Promise<DocumentNode>;
|
|
35
|
-
executeUpdateMutation(input: UpdateMutationInput, info: GraphQLResolveInfo): Promise<DocumentNode>;
|
|
36
|
-
executeRemoveMutation(id: string, info: GraphQLResolveInfo): Promise<void>;
|
|
37
|
-
};
|
|
38
|
-
export type Context = ReadContext & WriteContext;
|
|
39
|
-
export type UpdateMutationInput = {
|
|
40
|
-
id: string;
|
|
41
|
-
patch: Array<PatchOperationType>;
|
|
42
|
-
from?: DocumentData;
|
|
43
|
-
};
|
|
44
10
|
export type GraphQLNodeDefinitions = {
|
|
45
11
|
nodeInterface: GraphQLInterfaceType;
|
|
46
12
|
nodeField: GraphQLFieldConfig<unknown, Context>;
|
|
@@ -57,7 +23,7 @@ type RelationField = {
|
|
|
57
23
|
model: string;
|
|
58
24
|
isList: boolean;
|
|
59
25
|
};
|
|
60
|
-
type RelationFields = Record<string, RelationField
|
|
26
|
+
type RelationFields = Record<string, Array<RelationField>>;
|
|
61
27
|
export type SchemaBuilderParams = {
|
|
62
28
|
aliases?: Record<string, string>;
|
|
63
29
|
record: DocumentModelsRecord;
|
package/lib/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,eAAe,EAAY,MAAM,WAAW,CAAA;AAC/E,OAAO,KAAK,EACV,UAAU,EACV,YAAY,
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,eAAe,EAAY,MAAM,WAAW,CAAA;AAC/E,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EAEZ,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,WAAW,EAEX,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,WAAW,EAEX,SAAS,EACV,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAGL,eAAe,EAEf,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAI1B,sBAAsB,EACtB,KAAK,gBAAgB,EAErB,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,aAAa,EAKd,MAAM,SAAS,CAAA;AAiBhB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAgD3C,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,eAAe,GAAG,MAAM,GAAG,eAAe,CAE/E;AAED,wBAAgB,WAAW,CACzB,EAAE,EAAE,eAAe,GAAG,MAAM,EAC5B,QAAQ,EAAE,eAAe,GAAG,MAAM,GACjC,eAAe,CAGjB;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,gBAAgB,iDAE5C;AAED,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ACtB,IAAI;IA0BP,2BAA2B,CACzB,MAAM,EAAE,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,EAC/C,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,aAAa,GACtB,IAAI;IAkCP,YAAY,CACV,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,GACf,eAAe,GAAG,iBAAiB,GAAG,iBAAiB;IAa1D,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO;IAqB9D,gBAAgB,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,SAAK,GAUvB,eAAe;IAGjD,kBAAkB,CAAC,MAAM,EAAE,iBAAiB;CAO7C;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,oBAAoB,EAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,aAAa,CAEf"}
|
package/lib/schema.js
CHANGED
|
@@ -250,10 +250,11 @@ export class SchemaBuilder {
|
|
|
250
250
|
const isList = this._getReferenceSchema(relationRefID).type === 'array';
|
|
251
251
|
const relationID = getGlobalID(meta.relationModel, modelID).toString();
|
|
252
252
|
this._relationsTo[relationID] ??= {};
|
|
253
|
-
this._relationsTo[relationID][fieldName]
|
|
253
|
+
this._relationsTo[relationID][fieldName] ??= [];
|
|
254
|
+
this._relationsTo[relationID][fieldName].push({
|
|
254
255
|
model: modelIDstring,
|
|
255
256
|
isList
|
|
256
|
-
};
|
|
257
|
+
});
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
260
|
}
|
|
@@ -345,12 +346,16 @@ export class SchemaBuilder {
|
|
|
345
346
|
};
|
|
346
347
|
for (const iid of model.interfaces ?? []){
|
|
347
348
|
const interfaceID = getGlobalID(iid, id).toString();
|
|
348
|
-
for (const [fieldName,
|
|
349
|
-
|
|
349
|
+
for (const [fieldName, relations] of Object.entries(this._relationsTo[interfaceID] ?? {})){
|
|
350
|
+
for (const relation of relations){
|
|
351
|
+
this._buildRelationSubscriptions(fields, interfaceID, fieldName, relation);
|
|
352
|
+
}
|
|
350
353
|
}
|
|
351
354
|
}
|
|
352
|
-
for (const [fieldName,
|
|
353
|
-
|
|
355
|
+
for (const [fieldName, relations] of Object.entries(this._relationsTo[id] ?? {})){
|
|
356
|
+
for (const relation of relations){
|
|
357
|
+
this._buildRelationSubscriptions(fields, id, fieldName, relation);
|
|
358
|
+
}
|
|
354
359
|
}
|
|
355
360
|
}
|
|
356
361
|
return fields;
|
|
@@ -725,12 +730,16 @@ export class SchemaBuilder {
|
|
|
725
730
|
}
|
|
726
731
|
for (const iid of model.interfaces ?? []){
|
|
727
732
|
const interfaceID = getGlobalID(iid, id).toString();
|
|
728
|
-
for (const [fieldName,
|
|
729
|
-
|
|
733
|
+
for (const [fieldName, relations] of Object.entries(this._relationsTo[interfaceID] ?? {})){
|
|
734
|
+
for (const relation of relations){
|
|
735
|
+
this._buildRelationFields(fields, fieldName, relation);
|
|
736
|
+
}
|
|
730
737
|
}
|
|
731
738
|
}
|
|
732
|
-
for (const [fieldName,
|
|
733
|
-
|
|
739
|
+
for (const [fieldName, relations] of Object.entries(this._relationsTo[id] ?? {})){
|
|
740
|
+
for (const relation of relations){
|
|
741
|
+
this._buildRelationFields(fields, fieldName, relation);
|
|
742
|
+
}
|
|
734
743
|
}
|
|
735
744
|
}
|
|
736
745
|
return fields;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { DocumentData, DocumentFilter, DocumentOrderBy } from '@kubun/protocol';
|
|
2
|
+
import type { ConnectionArguments } from 'graphql-relay';
|
|
1
3
|
export type PatchAddOperation = {
|
|
2
4
|
op: 'add';
|
|
3
5
|
path: string;
|
|
@@ -23,4 +25,13 @@ export type PatchCopyOperation = {
|
|
|
23
25
|
path: string;
|
|
24
26
|
};
|
|
25
27
|
export type PatchOperation = PatchAddOperation | PatchCopyOperation | PatchMoveOperation | PatchRemoveOperation | PatchReplaceOperation;
|
|
28
|
+
export type AllConnectionArguments = ConnectionArguments & {
|
|
29
|
+
filter?: DocumentFilter;
|
|
30
|
+
orderBy?: DocumentOrderBy;
|
|
31
|
+
};
|
|
32
|
+
export type UpdateMutationInput = {
|
|
33
|
+
id: string;
|
|
34
|
+
patch: Array<PatchOperation>;
|
|
35
|
+
from?: DocumentData;
|
|
36
|
+
};
|
|
26
37
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAA;AAC3E,MAAM,MAAM,oBAAoB,GAAG;IAAE,EAAE,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AACjE,MAAM,MAAM,qBAAqB,GAAG;IAAE,EAAE,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAA;AACnF,MAAM,MAAM,kBAAkB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAC3E,MAAM,MAAM,kBAAkB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAC3E,MAAM,MAAM,cAAc,GACtB,iBAAiB,GACjB,kBAAkB,GAClB,kBAAkB,GAClB,oBAAoB,GACpB,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts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@@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/graphql",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -15,17 +15,19 @@
|
|
|
15
15
|
],
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@enkaku/async": "^0.12.0",
|
|
18
19
|
"@enkaku/codec": "^0.12.0",
|
|
19
20
|
"change-case": "^5.4.4",
|
|
20
|
-
"graphql": "^16.
|
|
21
|
+
"graphql": "^16.11.0",
|
|
21
22
|
"graphql-relay": "^0.10.2",
|
|
22
23
|
"graphql-scalars": "^1.24.2",
|
|
23
24
|
"multiformats": "^13.3.2",
|
|
24
|
-
"@kubun/
|
|
25
|
-
"@kubun/
|
|
25
|
+
"@kubun/id": "^0.3.0",
|
|
26
|
+
"@kubun/protocol": "^0.3.4"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"json-schema-typed": "^8.0.1"
|
|
29
|
+
"json-schema-typed": "^8.0.1",
|
|
30
|
+
"@kubun/db": "^0.3.3"
|
|
29
31
|
},
|
|
30
32
|
"scripts": {
|
|
31
33
|
"build:clean": "del lib",
|