@kubun/graphql 0.1.0 → 0.2.1
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/identifiers.d.ts +0 -2
- package/lib/identifiers.d.ts.map +1 -1
- package/lib/identifiers.js +4 -30
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -2
- package/lib/scalars.d.ts +2 -2
- package/lib/scalars.d.ts.map +1 -1
- package/lib/scalars.js +21 -15
- package/lib/schema.d.ts +20 -15
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +192 -63
- package/lib/utils.d.ts +3 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +4 -0
- package/package.json +6 -5
package/lib/identifiers.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { GraphQLScalarType } from 'graphql';
|
|
2
2
|
import type { JSONSchema } from 'json-schema-typed';
|
|
3
|
-
export declare const GraphQLCID: GraphQLScalarType<string, string>;
|
|
4
|
-
export declare const cidSchema: JSONSchema.String;
|
|
5
3
|
export declare const GraphQLAttachmentID: GraphQLScalarType<string, string>;
|
|
6
4
|
export declare const attachmentIDSchema: JSONSchema.String;
|
|
7
5
|
export declare const GraphQLDocID: GraphQLScalarType<string, string>;
|
package/lib/identifiers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,iBAAiB,EAAQ,MAAM,SAAS,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAWnD,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,iBAAiB,EAAQ,MAAM,SAAS,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAWnD,eAAO,MAAM,mBAAmB,mCAW9B,CAAA;AAEF,eAAO,MAAM,kBAAkB,EAAE,UAAU,CAAC,MAI3C,CAAA;AAWD,eAAO,MAAM,YAAY,mCAWvB,CAAA;AAEF,eAAO,MAAM,WAAW,EAAE,UAAU,CAAC,MAIpC,CAAA"}
|
package/lib/identifiers.js
CHANGED
|
@@ -1,31 +1,5 @@
|
|
|
1
1
|
import { AttachmentID, DocumentID } from '@kubun/id';
|
|
2
2
|
import { GraphQLError, GraphQLScalarType, Kind } from 'graphql';
|
|
3
|
-
import { CID } from 'multiformats/cid';
|
|
4
|
-
function validateCID(input) {
|
|
5
|
-
const cid = typeof input === 'string' ? CID.parse(input) : CID.asCID(input);
|
|
6
|
-
if (cid == null) {
|
|
7
|
-
throw new GraphQLError(`Could not parse input as CID: ${input}`);
|
|
8
|
-
}
|
|
9
|
-
return cid.toV1().toString();
|
|
10
|
-
}
|
|
11
|
-
export const GraphQLCID = new GraphQLScalarType({
|
|
12
|
-
name: 'ContentID',
|
|
13
|
-
description: 'A IPLD Content identifier (CID)',
|
|
14
|
-
specifiedByURL: 'https://github.com/multiformats/cid',
|
|
15
|
-
serialize: validateCID,
|
|
16
|
-
parseValue: validateCID,
|
|
17
|
-
parseLiteral (ast) {
|
|
18
|
-
if (ast.kind !== Kind.STRING) {
|
|
19
|
-
throw new GraphQLError(`Can only validate strings as ContentID but got a: ${ast.kind}`);
|
|
20
|
-
}
|
|
21
|
-
return validateCID(ast.value);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
export const cidSchema = {
|
|
25
|
-
type: 'string',
|
|
26
|
-
title: 'cid',
|
|
27
|
-
pattern: '^b[2-7a-z]{99}$'
|
|
28
|
-
};
|
|
29
3
|
function validateAttachmentID(input) {
|
|
30
4
|
if (typeof input !== 'string') {
|
|
31
5
|
throw new GraphQLError(`Invalid AttachmentID input: ${input}`);
|
|
@@ -48,8 +22,8 @@ export const GraphQLAttachmentID = new GraphQLScalarType({
|
|
|
48
22
|
});
|
|
49
23
|
export const attachmentIDSchema = {
|
|
50
24
|
type: 'string',
|
|
51
|
-
title: '
|
|
52
|
-
pattern: '^k[0-9a-z]{
|
|
25
|
+
title: 'AttachmentID',
|
|
26
|
+
pattern: '^k[0-9a-z]{10,120}$'
|
|
53
27
|
};
|
|
54
28
|
function validateDocID(input) {
|
|
55
29
|
if (typeof input !== 'string') {
|
|
@@ -73,6 +47,6 @@ export const GraphQLDocID = new GraphQLScalarType({
|
|
|
73
47
|
});
|
|
74
48
|
export const docIDSchema = {
|
|
75
49
|
type: 'string',
|
|
76
|
-
title: '
|
|
77
|
-
pattern: '^k[0-9a-z]{
|
|
50
|
+
title: 'DocID',
|
|
51
|
+
pattern: '^k[0-9a-z]{10,120}$'
|
|
78
52
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { GraphQLAttachmentID, GraphQLDocID } from './identifiers.js';
|
|
2
2
|
export * as scalars from './scalars.js';
|
|
3
|
-
export { type DocumentType, SchemaBuilder, type SchemaBuilderParams, type SharedDefinitions, } from './schema.js';
|
|
3
|
+
export { type DocumentType, PatchOperation, SchemaBuilder, type SchemaBuilderParams, type SharedDefinitions, toList, } from './schema.js';
|
|
4
|
+
export { getUniqueDocValue } from './utils.js';
|
|
4
5
|
//# 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,
|
|
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,OAAO,EACL,KAAK,YAAY,EACjB,cAAc,EACd,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,MAAM,GACP,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { GraphQLAttachmentID, GraphQLDocID } from './identifiers.js';
|
|
2
2
|
export * as scalars from './scalars.js';
|
|
3
|
-
export { SchemaBuilder } from './schema.js';
|
|
3
|
+
export { PatchOperation, SchemaBuilder, toList } from './schema.js';
|
|
4
|
+
export { getUniqueDocValue } from './utils.js';
|
package/lib/scalars.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { JSONSchema } from 'json-schema-typed';
|
|
2
|
-
export { attachmentIDSchema,
|
|
3
|
-
export declare const bigIntSchema: JSONSchema.
|
|
2
|
+
export { attachmentIDSchema, docIDSchema } from './identifiers.js';
|
|
3
|
+
export declare const bigIntSchema: JSONSchema.Integer;
|
|
4
4
|
export declare const didSchema: JSONSchema.String;
|
|
5
5
|
export declare const dateTimeSchema: JSONSchema.String;
|
|
6
6
|
export declare const durationSchema: JSONSchema.String;
|
package/lib/scalars.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scalars.d.ts","sourceRoot":"","sources":["../src/scalars.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scalars.d.ts","sourceRoot":"","sources":["../src/scalars.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAMlE,eAAO,MAAM,YAAY,oBAAwD,CAAA;AACjF,eAAO,MAAM,SAAS,mBAAiC,CAAA;AACvD,eAAO,MAAM,cAAc,mBAAsC,CAAA;AACjE,eAAO,MAAM,cAAc,mBAAsC,CAAA;AACjE,eAAO,MAAM,gBAAgB,mBAAwC,CAAA;AACrE,eAAO,MAAM,cAAc,mBAAyD,CAAA;AACpF,eAAO,MAAM,eAAe,mBAAuC,CAAA;AACnE,eAAO,MAAM,mBAAmB,mBAA2C,CAAA;AAC3E,eAAO,MAAM,eAAe,mBAAuC,CAAA;AACnE,eAAO,MAAM,YAAY,mBAAoC,CAAA;AAC7D,eAAO,MAAM,eAAe,mBAA0D,CAAA;AACtF,eAAO,MAAM,cAAc,mBAAsC,CAAA;AACjE,eAAO,MAAM,SAAS,mBAAiC,CAAA;AACvD,eAAO,MAAM,eAAe,mBAAuC,CAAA"}
|
package/lib/scalars.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { GraphQLBigInt, GraphQLDID, GraphQLDateTime, GraphQLDuration, GraphQLJSONObject, GraphQLLatitude, GraphQLLocalDate, GraphQLLocalDateTime, GraphQLLocalTime, GraphQLLocale, GraphQLLongitude, GraphQLTimeZone, GraphQLURL, GraphQLUtcOffset } from 'graphql-scalars';
|
|
2
|
-
export { attachmentIDSchema,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
12
|
-
export const
|
|
13
|
-
export const
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
2
|
+
export { attachmentIDSchema, docIDSchema } from './identifiers.js';
|
|
3
|
+
function createScalarSchema(type) {
|
|
4
|
+
return {
|
|
5
|
+
...type.extensions.jsonSchema,
|
|
6
|
+
title: type.name
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export const bigIntSchema = createScalarSchema(GraphQLBigInt);
|
|
10
|
+
export const didSchema = createScalarSchema(GraphQLDID);
|
|
11
|
+
export const dateTimeSchema = createScalarSchema(GraphQLDateTime);
|
|
12
|
+
export const durationSchema = createScalarSchema(GraphQLDuration);
|
|
13
|
+
export const jsonObjectSchema = createScalarSchema(GraphQLJSONObject);
|
|
14
|
+
export const latitudeSchema = createScalarSchema(GraphQLLatitude);
|
|
15
|
+
export const localDateSchema = createScalarSchema(GraphQLLocalDate);
|
|
16
|
+
export const localDateTimeSchema = createScalarSchema(GraphQLLocalDateTime);
|
|
17
|
+
export const localTimeSchema = createScalarSchema(GraphQLLocalTime);
|
|
18
|
+
export const localeSchema = createScalarSchema(GraphQLLocale);
|
|
19
|
+
export const longitudeSchema = createScalarSchema(GraphQLLongitude);
|
|
20
|
+
export const timeZoneSchema = createScalarSchema(GraphQLTimeZone);
|
|
21
|
+
export const urlSchema = createScalarSchema(GraphQLURL);
|
|
22
|
+
export const utcOffsetSchema = createScalarSchema(GraphQLUtcOffset);
|
package/lib/schema.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { AttachmentID } 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 toList(type: GraphQLInputType): GraphQLList<GraphQLNonNull<GraphQLInputType>>;
|
|
6
|
+
export declare const PatchOperation: GraphQLInputObjectType;
|
|
5
7
|
export type DocumentType = {
|
|
6
8
|
id: string;
|
|
7
9
|
model: string;
|
|
@@ -27,6 +29,7 @@ export type SchemaBuilderParams = {
|
|
|
27
29
|
};
|
|
28
30
|
export declare class SchemaBuilder<Document extends DocumentType = DocumentType, Context extends ContextType = ContextType, Definitions extends SharedDefinitions<Document, Context> = SharedDefinitions<Document, Context>> {
|
|
29
31
|
_aliases: Record<string, string>;
|
|
32
|
+
_definitions: Definitions | undefined;
|
|
30
33
|
_record: DocumentModelsRecord;
|
|
31
34
|
_references: ReferencesRecordModel;
|
|
32
35
|
_relationsTo: Record<string, Record<string, string>>;
|
|
@@ -40,22 +43,24 @@ export declare class SchemaBuilder<Document extends DocumentType = DocumentType,
|
|
|
40
43
|
resolveList(model: string | null, ids: Array<string>, ctx: Context): Promise<Array<Document>>;
|
|
41
44
|
buildMutations(id: string, definitions: Definitions): void;
|
|
42
45
|
build(): GraphQLSchema;
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
_getDefinitions(): Definitions;
|
|
47
|
+
_getReference(path: string, parentName?: string): GraphQLOutputType;
|
|
48
|
+
_getReferenceInput(path: string, isPartial: boolean, parentName?: string): GraphQLInputType;
|
|
45
49
|
_buildSharedDefinitions(): Definitions;
|
|
46
|
-
_buildDocument(id: string
|
|
47
|
-
_buildDocumentInput(id: string, model: DocumentModel
|
|
48
|
-
_buildReferenceFilterInput(path: string,
|
|
49
|
-
_buildReferenceOrderByInput(path: string,
|
|
50
|
-
_buildObjectFilterInput(id: string, schema: DocumentModelSchema | ObjectModel,
|
|
51
|
-
_buildObjectOrderByInput(id: string, schema: DocumentModelSchema | ObjectModel,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
_buildDocument(id: string): GraphQLObjectType<Document, Context>;
|
|
51
|
+
_buildDocumentInput(id: string, model: DocumentModel): void;
|
|
52
|
+
_buildReferenceFilterInput(path: string, parentName?: string): GraphQLInputType;
|
|
53
|
+
_buildReferenceOrderByInput(path: string, parentName?: string): GraphQLInputType | null;
|
|
54
|
+
_buildObjectFilterInput(id: string, schema: DocumentModelSchema | ObjectModel, parentName?: string, isDocument?: boolean): GraphQLInputObjectType;
|
|
55
|
+
_buildObjectOrderByInput(id: string, schema: DocumentModelSchema | ObjectModel, parentName?: string, isDocument?: boolean): GraphQLInputObjectType;
|
|
56
|
+
_buildSetInputObjectType(id: string, withFields: Array<string>, relationField?: string): GraphQLInputObjectType;
|
|
57
|
+
_buildReference(id: string, schema: TypeModel, parentName?: string): GraphQLOutputType;
|
|
58
|
+
_buildScalar(id: string, schema: ScalarModel, asInput?: boolean): GraphQLScalarType;
|
|
59
|
+
_buildArray(schema: ArrayModel, parentName?: string): GraphQLList<GraphQLNonNull<GraphQLOutputType>>;
|
|
60
|
+
_buildObject(id: string, schema: ObjectModel, parentName?: string): GraphQLObjectType;
|
|
61
|
+
_buildObjectFields(id: string, schema: DocumentModelSchema | ObjectModel, model?: DocumentModel): Record<string, GraphQLFieldConfig<Document, Context>>;
|
|
62
|
+
_buildString(schema: StringModel, asInput: boolean): GraphQLEnumType | GraphQLObjectType | GraphQLScalarType;
|
|
63
|
+
_buildCustomString(schema: StringCustomModel, asInput: boolean): GraphQLScalarType<unknown, unknown> | GraphQLObjectType<string, Context> | GraphQLObjectType<AttachmentID, Context>;
|
|
59
64
|
_buildEnumString(schema: StringEnumModel): GraphQLEnumType;
|
|
60
65
|
_buildFormatString(schema: StringFormatModel): GraphQLScalarType<unknown, unknown>;
|
|
61
66
|
}
|
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,
|
|
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,EACh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EACV,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,EACzB,aAAa,CAAC,EAAE,MAAM,GACrB,sBAAsB;IA4BzB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,SAAK,GAAG,iBAAiB;IAiBlF,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,UAAQ,GAAG,iBAAiB;IAkBjF,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,SAAK,GAAG,WAAW,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IAOhG,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,SAAK,GAAG,iBAAiB;IAKjF,kBAAkB,CAChB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,mBAAmB,GAAG,WAAW,EACzC,KAAK,CAAC,EAAE,aAAa,GACpB,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IA6ExD,YAAY,CACV,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,OAAO,GACf,eAAe,GAAG,iBAAiB,GAAG,iBAAiB;IAU1D,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,OAAO;IAqB9D,gBAAgB,CAAC,MAAM,EAAE,eAAe;IAQxC,kBAAkB,CAAC,MAAM,EAAE,iBAAiB;CAO7C"}
|
package/lib/schema.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AttachmentID, DocumentID,
|
|
1
|
+
import { AttachmentID, DocumentID, DocumentModelID, decodeID } from '@kubun/id';
|
|
2
2
|
import { REFERENCE_PREFIX } from '@kubun/protocol';
|
|
3
3
|
import { pascalCase } from 'change-case';
|
|
4
4
|
import { GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLString, isEnumType, isListType, isNonNullType } from 'graphql';
|
|
5
5
|
import { connectionArgs, connectionDefinitions, nodeDefinitions } from 'graphql-relay';
|
|
6
|
-
import { GraphQLDID, GraphQLDuration, GraphQLURL } from 'graphql-scalars';
|
|
7
|
-
import { GraphQLAttachmentID,
|
|
6
|
+
import { GraphQLDID, GraphQLDuration, GraphQLJSON, GraphQLURL } from 'graphql-scalars';
|
|
7
|
+
import { GraphQLAttachmentID, GraphQLDocID } from './identifiers.js';
|
|
8
|
+
import { getUniqueDocValue } from './utils.js';
|
|
8
9
|
const STRING_FORMATS = {
|
|
9
10
|
date: GraphQLString,
|
|
10
11
|
time: GraphQLString,
|
|
@@ -14,14 +15,13 @@ const STRING_FORMATS = {
|
|
|
14
15
|
};
|
|
15
16
|
const STRING_TITLES = {
|
|
16
17
|
attachmentid: GraphQLAttachmentID,
|
|
17
|
-
cid: GraphQLCID,
|
|
18
18
|
did: GraphQLDID,
|
|
19
19
|
docid: GraphQLDocID
|
|
20
20
|
};
|
|
21
21
|
function isList(type) {
|
|
22
22
|
return isListType(type) || isNonNullType(type) && isListType(type.ofType);
|
|
23
23
|
}
|
|
24
|
-
function toList(type) {
|
|
24
|
+
export function toList(type) {
|
|
25
25
|
return new GraphQLList(new GraphQLNonNull(type));
|
|
26
26
|
}
|
|
27
27
|
function toOuputList(type) {
|
|
@@ -127,6 +127,57 @@ const VALUE_FILTER_INPUT_TYPES = {
|
|
|
127
127
|
GraphQLInt: 'IntValueFilter',
|
|
128
128
|
GraphQLString: 'StringValueFilter'
|
|
129
129
|
};
|
|
130
|
+
const PatchSetOperation = new GraphQLInputObjectType({
|
|
131
|
+
name: 'PatchSetOperation',
|
|
132
|
+
fields: {
|
|
133
|
+
path: {
|
|
134
|
+
type: new GraphQLNonNull(GraphQLString)
|
|
135
|
+
},
|
|
136
|
+
value: {
|
|
137
|
+
type: GraphQLJSON
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const PatchRemoveOperation = new GraphQLInputObjectType({
|
|
142
|
+
name: 'PatchRemoveOperation',
|
|
143
|
+
fields: {
|
|
144
|
+
path: {
|
|
145
|
+
type: new GraphQLNonNull(GraphQLString)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const PatchDestinationOperation = new GraphQLInputObjectType({
|
|
150
|
+
name: 'PatchDestinationOperation',
|
|
151
|
+
fields: {
|
|
152
|
+
from: {
|
|
153
|
+
type: new GraphQLNonNull(GraphQLString)
|
|
154
|
+
},
|
|
155
|
+
path: {
|
|
156
|
+
type: new GraphQLNonNull(GraphQLString)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
export const PatchOperation = new GraphQLInputObjectType({
|
|
161
|
+
name: 'PatchOperation',
|
|
162
|
+
isOneOf: true,
|
|
163
|
+
fields: {
|
|
164
|
+
add: {
|
|
165
|
+
type: PatchSetOperation
|
|
166
|
+
},
|
|
167
|
+
remove: {
|
|
168
|
+
type: PatchRemoveOperation
|
|
169
|
+
},
|
|
170
|
+
replace: {
|
|
171
|
+
type: PatchSetOperation
|
|
172
|
+
},
|
|
173
|
+
copy: {
|
|
174
|
+
type: PatchDestinationOperation
|
|
175
|
+
},
|
|
176
|
+
move: {
|
|
177
|
+
type: PatchDestinationOperation
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
130
181
|
const OrderByDirection = new GraphQLEnumType({
|
|
131
182
|
name: 'OrderByDirection',
|
|
132
183
|
values: {
|
|
@@ -141,6 +192,7 @@ const OrderByDirection = new GraphQLEnumType({
|
|
|
141
192
|
export class SchemaBuilder {
|
|
142
193
|
// Mapping of model or references IDs to their GraphQL object names
|
|
143
194
|
_aliases;
|
|
195
|
+
_definitions;
|
|
144
196
|
_record;
|
|
145
197
|
_references = {};
|
|
146
198
|
_relationsTo = {};
|
|
@@ -148,19 +200,20 @@ export class SchemaBuilder {
|
|
|
148
200
|
OrderByDirection
|
|
149
201
|
};
|
|
150
202
|
_inputObjects = {
|
|
151
|
-
...VALUE_FILTER_INPUTS
|
|
203
|
+
...VALUE_FILTER_INPUTS,
|
|
204
|
+
PatchOperation
|
|
152
205
|
};
|
|
153
206
|
_mutations = {};
|
|
154
207
|
constructor(params){
|
|
155
208
|
this._aliases = params.aliases ?? {};
|
|
156
209
|
this._record = params.record;
|
|
157
210
|
for (const [id, model] of Object.entries(params.record)){
|
|
158
|
-
const modelID =
|
|
211
|
+
const modelID = DocumentModelID.fromString(id);
|
|
159
212
|
Object.assign(this._references, model.schema.$defs ?? {});
|
|
160
213
|
// Extract inverse relations
|
|
161
214
|
for (const [fieldName, meta] of Object.entries(model.fieldsMeta)){
|
|
162
215
|
if (meta.relationModel != null) {
|
|
163
|
-
const relationModelID =
|
|
216
|
+
const relationModelID = DocumentModelID.fromString(meta.relationModel);
|
|
164
217
|
const globalID = relationModelID.isLocal ? relationModelID.toGlobal(modelID) : relationModelID;
|
|
165
218
|
const relationID = globalID.toString();
|
|
166
219
|
this._relationsTo[relationID] ??= {};
|
|
@@ -186,19 +239,16 @@ export class SchemaBuilder {
|
|
|
186
239
|
}
|
|
187
240
|
build() {
|
|
188
241
|
const definitions = this._buildSharedDefinitions();
|
|
242
|
+
this._definitions = definitions;
|
|
189
243
|
const queryFields = {
|
|
190
244
|
nodes: definitions.nodesField,
|
|
191
245
|
...definitions.queryFields
|
|
192
246
|
};
|
|
193
|
-
// TODO: is this needed?
|
|
194
|
-
// for (const [id, schema] of Object.entries(this._references)) {
|
|
195
|
-
// this._buildReference(id, schema, definitions)
|
|
196
|
-
// }
|
|
197
247
|
for (const id of Object.keys(this._record)){
|
|
198
|
-
this._buildDocument(id
|
|
248
|
+
this._buildDocument(id);
|
|
199
249
|
this.buildMutations(id, definitions);
|
|
200
250
|
const name = this._aliases[id];
|
|
201
|
-
queryFields[`
|
|
251
|
+
queryFields[`all${name}`] = {
|
|
202
252
|
type: this._types[`${id}-connection`],
|
|
203
253
|
args: {
|
|
204
254
|
...connectionArgs,
|
|
@@ -226,7 +276,13 @@ export class SchemaBuilder {
|
|
|
226
276
|
};
|
|
227
277
|
return new GraphQLSchema(schemaFields);
|
|
228
278
|
}
|
|
229
|
-
|
|
279
|
+
_getDefinitions() {
|
|
280
|
+
if (this._definitions == null) {
|
|
281
|
+
throw new Error('Definitions must be initialized');
|
|
282
|
+
}
|
|
283
|
+
return this._definitions;
|
|
284
|
+
}
|
|
285
|
+
_getReference(path, parentName) {
|
|
230
286
|
const id = path.slice(REFERENCE_PREFIX.length);
|
|
231
287
|
const type = this._types[id];
|
|
232
288
|
if (type != null) {
|
|
@@ -236,16 +292,16 @@ export class SchemaBuilder {
|
|
|
236
292
|
if (schema == null) {
|
|
237
293
|
throw new Error(`Could not find reference: ${id}`);
|
|
238
294
|
}
|
|
239
|
-
return this._buildReference(id, schema,
|
|
295
|
+
return this._buildReference(id, schema, parentName);
|
|
240
296
|
}
|
|
241
|
-
_getReferenceInput(path,
|
|
297
|
+
_getReferenceInput(path, isPartial, parentName = '') {
|
|
242
298
|
const id = path.slice(REFERENCE_PREFIX.length);
|
|
243
299
|
const schema = this._references[id];
|
|
244
300
|
if (schema == null) {
|
|
245
301
|
throw new Error(`Could not find reference: ${id}`);
|
|
246
302
|
}
|
|
247
303
|
if (schema.type === 'array') {
|
|
248
|
-
const itemType = this._getReferenceInput(schema.items.$ref,
|
|
304
|
+
const itemType = this._getReferenceInput(schema.items.$ref, false, schema.title);
|
|
249
305
|
return new GraphQLList(new GraphQLNonNull(itemType));
|
|
250
306
|
}
|
|
251
307
|
if (schema.type === 'object') {
|
|
@@ -256,7 +312,7 @@ export class SchemaBuilder {
|
|
|
256
312
|
}
|
|
257
313
|
const fields = {};
|
|
258
314
|
for (const [key, value] of Object.entries(schema.properties)){
|
|
259
|
-
const type = this._getReferenceInput(value.$ref,
|
|
315
|
+
const type = this._getReferenceInput(value.$ref, isPartial, schema.title);
|
|
260
316
|
fields[key] = {
|
|
261
317
|
type: isPartial || !schema.required.includes(key) ? type : new GraphQLNonNull(type)
|
|
262
318
|
};
|
|
@@ -269,7 +325,7 @@ export class SchemaBuilder {
|
|
|
269
325
|
this._inputObjects[inputID] = input;
|
|
270
326
|
return input;
|
|
271
327
|
}
|
|
272
|
-
return this._buildScalar(id, schema,
|
|
328
|
+
return this._buildScalar(id, schema, true);
|
|
273
329
|
}
|
|
274
330
|
_buildSharedDefinitions() {
|
|
275
331
|
const nodeDefs = nodeDefinitions(async (id, ctx)=>{
|
|
@@ -301,11 +357,56 @@ export class SchemaBuilder {
|
|
|
301
357
|
},
|
|
302
358
|
isViewer: {
|
|
303
359
|
type: new GraphQLNonNull(GraphQLBoolean),
|
|
304
|
-
description: 'Whether the
|
|
360
|
+
description: 'Whether the authenticated request issuer is this account or not',
|
|
305
361
|
resolve: (did, _, ctx)=>this.getViewer(ctx) === did
|
|
306
362
|
}
|
|
307
363
|
};
|
|
308
|
-
|
|
364
|
+
for (const [id, model] of Object.entries(this._record)){
|
|
365
|
+
switch(model.behavior){
|
|
366
|
+
case 'interface':
|
|
367
|
+
continue;
|
|
368
|
+
case 'default':
|
|
369
|
+
{
|
|
370
|
+
const name = this._aliases[id];
|
|
371
|
+
config[`all${name}`] = {
|
|
372
|
+
type: this._types[`${id}-connection`],
|
|
373
|
+
args: {
|
|
374
|
+
...connectionArgs,
|
|
375
|
+
filter: {
|
|
376
|
+
type: this._inputObjects[`${id}-filter`]
|
|
377
|
+
},
|
|
378
|
+
orderBy: {
|
|
379
|
+
type: toList(this._inputObjects[`${id}-order`])
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
resolve: async (owner, args, ctx)=>{
|
|
383
|
+
return await this.resolveConnection(id, {
|
|
384
|
+
...args,
|
|
385
|
+
owner
|
|
386
|
+
}, ctx);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
case 'unique':
|
|
392
|
+
{
|
|
393
|
+
const name = this._aliases[id];
|
|
394
|
+
config[name] = {
|
|
395
|
+
type: this._types[id],
|
|
396
|
+
args: model.uniqueFields.length ? {
|
|
397
|
+
with: {
|
|
398
|
+
type: this._buildSetInputObjectType(id, model.uniqueFields)
|
|
399
|
+
}
|
|
400
|
+
} : {},
|
|
401
|
+
resolve: async (owner, args, ctx)=>{
|
|
402
|
+
const unique = getUniqueDocValue(model.uniqueFields, args.with);
|
|
403
|
+
const docID = await DocumentID.create(id, owner, unique);
|
|
404
|
+
return await this.loadDocument(docID.toString(), ctx);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
309
410
|
return config;
|
|
310
411
|
}
|
|
311
412
|
});
|
|
@@ -319,9 +420,6 @@ export class SchemaBuilder {
|
|
|
319
420
|
type: new GraphQLNonNull(GraphQLID),
|
|
320
421
|
resolve: (aid)=>aid.toString()
|
|
321
422
|
},
|
|
322
|
-
cid: {
|
|
323
|
-
type: new GraphQLNonNull(GraphQLCID)
|
|
324
|
-
},
|
|
325
423
|
contentLength: {
|
|
326
424
|
type: new GraphQLNonNull(GraphQLInt)
|
|
327
425
|
},
|
|
@@ -362,7 +460,7 @@ export class SchemaBuilder {
|
|
|
362
460
|
node: nodeDefs.nodeField,
|
|
363
461
|
viewer: {
|
|
364
462
|
type: accountObject,
|
|
365
|
-
description: 'Account
|
|
463
|
+
description: 'Account issuing the request, if authenticated',
|
|
366
464
|
resolve: (_self, _args, ctx)=>this.getViewer(ctx)
|
|
367
465
|
}
|
|
368
466
|
};
|
|
@@ -375,7 +473,7 @@ export class SchemaBuilder {
|
|
|
375
473
|
queryFields
|
|
376
474
|
};
|
|
377
475
|
}
|
|
378
|
-
_buildDocument(id
|
|
476
|
+
_buildDocument(id) {
|
|
379
477
|
if (this._types[id] != null) {
|
|
380
478
|
return this._types[id];
|
|
381
479
|
}
|
|
@@ -383,6 +481,7 @@ export class SchemaBuilder {
|
|
|
383
481
|
if (model == null) {
|
|
384
482
|
throw new Error(`Could not find model id: ${id}`);
|
|
385
483
|
}
|
|
484
|
+
const definitions = this._getDefinitions();
|
|
386
485
|
this._aliases[id] ??= pascalCase(model.name);
|
|
387
486
|
const nodeType = new GraphQLObjectType({
|
|
388
487
|
name: this._aliases[id],
|
|
@@ -391,7 +490,7 @@ export class SchemaBuilder {
|
|
|
391
490
|
definitions.nodeInterface
|
|
392
491
|
],
|
|
393
492
|
fields: ()=>{
|
|
394
|
-
return this._buildObjectFields(id, model.schema,
|
|
493
|
+
return this._buildObjectFields(id, model.schema, model);
|
|
395
494
|
}
|
|
396
495
|
});
|
|
397
496
|
const { connectionType, edgeType } = connectionDefinitions({
|
|
@@ -400,12 +499,12 @@ export class SchemaBuilder {
|
|
|
400
499
|
this._types[id] = nodeType;
|
|
401
500
|
this._types[`${id}-connection`] = connectionType;
|
|
402
501
|
this._types[`${id}-edge`] = edgeType;
|
|
403
|
-
this._buildDocumentInput(id, model
|
|
404
|
-
this._buildObjectFilterInput(id, model.schema,
|
|
405
|
-
this._buildObjectOrderByInput(id, model.schema,
|
|
502
|
+
this._buildDocumentInput(id, model);
|
|
503
|
+
this._buildObjectFilterInput(id, model.schema, model.name, true);
|
|
504
|
+
this._buildObjectOrderByInput(id, model.schema, model.name, true);
|
|
406
505
|
return nodeType;
|
|
407
506
|
}
|
|
408
|
-
_buildDocumentInput(id, model
|
|
507
|
+
_buildDocumentInput(id, model) {
|
|
409
508
|
if (model.behavior === 'interface') {
|
|
410
509
|
// No mutations for interfaces
|
|
411
510
|
return;
|
|
@@ -413,17 +512,17 @@ export class SchemaBuilder {
|
|
|
413
512
|
const setFields = {};
|
|
414
513
|
const updateFields = {};
|
|
415
514
|
for (const [key, value] of Object.entries(model.schema.properties)){
|
|
416
|
-
const setType = this._getReferenceInput(value.$ref,
|
|
515
|
+
const setType = this._getReferenceInput(value.$ref, false);
|
|
417
516
|
setFields[key] = {
|
|
418
517
|
type: model.schema.required.includes(key) ? new GraphQLNonNull(setType) : setType
|
|
419
518
|
};
|
|
420
519
|
updateFields[key] = {
|
|
421
|
-
type: this._getReferenceInput(value.$ref,
|
|
520
|
+
type: this._getReferenceInput(value.$ref, true)
|
|
422
521
|
};
|
|
423
522
|
}
|
|
424
523
|
const name = this._aliases[id];
|
|
425
524
|
this._inputObjects[id] = new GraphQLInputObjectType({
|
|
426
|
-
name: model.behavior === '
|
|
525
|
+
name: model.behavior === 'default' ? `Create${name}` : `Set${name}`,
|
|
427
526
|
fields: setFields
|
|
428
527
|
});
|
|
429
528
|
this._inputObjects[`${id}-update`] = new GraphQLInputObjectType({
|
|
@@ -431,18 +530,18 @@ export class SchemaBuilder {
|
|
|
431
530
|
fields: updateFields
|
|
432
531
|
});
|
|
433
532
|
}
|
|
434
|
-
_buildReferenceFilterInput(path,
|
|
533
|
+
_buildReferenceFilterInput(path, parentName = '') {
|
|
435
534
|
const id = path.slice(REFERENCE_PREFIX.length);
|
|
436
535
|
const schema = this._references[id];
|
|
437
536
|
if (schema == null) {
|
|
438
537
|
throw new Error(`Could not find reference: ${id}`);
|
|
439
538
|
}
|
|
440
539
|
if (schema.type === 'object') {
|
|
441
|
-
return this._buildObjectFilterInput(id, schema,
|
|
540
|
+
return this._buildObjectFilterInput(id, schema, parentName);
|
|
442
541
|
}
|
|
443
542
|
if (schema.type === 'array') {
|
|
444
543
|
const name = this._aliases[id] ?? pascalCase(parentName + schema.title);
|
|
445
|
-
const itemType = this._buildReferenceFilterInput(schema.items.$ref,
|
|
544
|
+
const itemType = this._buildReferenceFilterInput(schema.items.$ref, schema.title);
|
|
446
545
|
return new GraphQLInputObjectType({
|
|
447
546
|
name: `${name}Filter`,
|
|
448
547
|
isOneOf: true,
|
|
@@ -459,7 +558,7 @@ export class SchemaBuilder {
|
|
|
459
558
|
}
|
|
460
559
|
});
|
|
461
560
|
}
|
|
462
|
-
const scalar = this._buildScalar(id, schema,
|
|
561
|
+
const scalar = this._buildScalar(id, schema, true);
|
|
463
562
|
const knownFilter = VALUE_FILTER_INPUT_TYPES[scalar.name];
|
|
464
563
|
if (knownFilter != null) {
|
|
465
564
|
return this._inputObjects[knownFilter];
|
|
@@ -470,7 +569,7 @@ export class SchemaBuilder {
|
|
|
470
569
|
}
|
|
471
570
|
return this._inputObjects[filter.name];
|
|
472
571
|
}
|
|
473
|
-
_buildReferenceOrderByInput(path,
|
|
572
|
+
_buildReferenceOrderByInput(path, parentName = '') {
|
|
474
573
|
const id = path.slice(REFERENCE_PREFIX.length);
|
|
475
574
|
const schema = this._references[id];
|
|
476
575
|
if (schema == null) {
|
|
@@ -480,12 +579,12 @@ export class SchemaBuilder {
|
|
|
480
579
|
case 'array':
|
|
481
580
|
return null;
|
|
482
581
|
case 'object':
|
|
483
|
-
return this._buildObjectOrderByInput(id, schema,
|
|
582
|
+
return this._buildObjectOrderByInput(id, schema, parentName);
|
|
484
583
|
default:
|
|
485
584
|
return OrderByDirection;
|
|
486
585
|
}
|
|
487
586
|
}
|
|
488
|
-
_buildObjectFilterInput(id, schema,
|
|
587
|
+
_buildObjectFilterInput(id, schema, parentName = '', isDocument = false) {
|
|
489
588
|
const inputID = `${id}-filter`;
|
|
490
589
|
const existing = this._inputObjects[inputID];
|
|
491
590
|
if (existing != null) {
|
|
@@ -498,7 +597,7 @@ export class SchemaBuilder {
|
|
|
498
597
|
}
|
|
499
598
|
} : {};
|
|
500
599
|
for (const [key, value] of Object.entries(schema.properties)){
|
|
501
|
-
const type = this._buildReferenceFilterInput(value.$ref,
|
|
600
|
+
const type = this._buildReferenceFilterInput(value.$ref, name);
|
|
502
601
|
fields[key] = {
|
|
503
602
|
type
|
|
504
603
|
};
|
|
@@ -528,7 +627,7 @@ export class SchemaBuilder {
|
|
|
528
627
|
this._inputObjects[inputID] = input;
|
|
529
628
|
return input;
|
|
530
629
|
}
|
|
531
|
-
_buildObjectOrderByInput(id, schema,
|
|
630
|
+
_buildObjectOrderByInput(id, schema, parentName = '', isDocument = false) {
|
|
532
631
|
const inputID = `${id}-order`;
|
|
533
632
|
const existing = this._inputObjects[inputID];
|
|
534
633
|
if (existing != null) {
|
|
@@ -544,7 +643,7 @@ export class SchemaBuilder {
|
|
|
544
643
|
}
|
|
545
644
|
} : {};
|
|
546
645
|
for (const [key, value] of Object.entries(schema.properties)){
|
|
547
|
-
const type = this._buildReferenceOrderByInput(value.$ref,
|
|
646
|
+
const type = this._buildReferenceOrderByInput(value.$ref, name);
|
|
548
647
|
if (type != null) {
|
|
549
648
|
fields[key] = {
|
|
550
649
|
type
|
|
@@ -559,22 +658,50 @@ export class SchemaBuilder {
|
|
|
559
658
|
this._inputObjects[inputID] = input;
|
|
560
659
|
return input;
|
|
561
660
|
}
|
|
562
|
-
|
|
661
|
+
_buildSetInputObjectType(id, withFields, relationField) {
|
|
662
|
+
const relationFieldName = relationField ? pascalCase(relationField) : '';
|
|
663
|
+
const inputID = `${id}-with-${relationFieldName}`;
|
|
664
|
+
const existing = this._inputObjects[inputID];
|
|
665
|
+
if (existing != null) {
|
|
666
|
+
return existing;
|
|
667
|
+
}
|
|
668
|
+
const model = this._record[id];
|
|
669
|
+
const name = this._aliases[id];
|
|
670
|
+
this._inputObjects[inputID] = new GraphQLInputObjectType({
|
|
671
|
+
name: `With${relationFieldName}${name}Input`,
|
|
672
|
+
fields: ()=>{
|
|
673
|
+
const fields = {};
|
|
674
|
+
for (const fieldName of withFields){
|
|
675
|
+
const field = model.schema.properties[fieldName];
|
|
676
|
+
if (field == null) {
|
|
677
|
+
throw new Error(`Field ${fieldName} not found on model ${name}`);
|
|
678
|
+
}
|
|
679
|
+
const type = this._getReferenceInput(field.$ref, false);
|
|
680
|
+
fields[fieldName] = {
|
|
681
|
+
type: new GraphQLNonNull(type)
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
return fields;
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
return this._inputObjects[inputID];
|
|
688
|
+
}
|
|
689
|
+
_buildReference(id, schema, parentName = '') {
|
|
563
690
|
if (this._types[id] != null) {
|
|
564
691
|
return this._types[id];
|
|
565
692
|
}
|
|
566
693
|
switch(schema.type){
|
|
567
694
|
case 'array':
|
|
568
|
-
this._types[id] = this._buildArray(schema,
|
|
695
|
+
this._types[id] = this._buildArray(schema, parentName);
|
|
569
696
|
return this._types[id];
|
|
570
697
|
case 'object':
|
|
571
|
-
this._types[id] = this._buildObject(id, schema,
|
|
698
|
+
this._types[id] = this._buildObject(id, schema, parentName);
|
|
572
699
|
return this._types[id];
|
|
573
700
|
default:
|
|
574
|
-
return this._buildScalar(id, schema
|
|
701
|
+
return this._buildScalar(id, schema);
|
|
575
702
|
}
|
|
576
703
|
}
|
|
577
|
-
_buildScalar(id, schema,
|
|
704
|
+
_buildScalar(id, schema, asInput = false) {
|
|
578
705
|
switch(schema.type){
|
|
579
706
|
case 'boolean':
|
|
580
707
|
this._types[id] = GraphQLBoolean;
|
|
@@ -586,23 +713,24 @@ export class SchemaBuilder {
|
|
|
586
713
|
this._types[id] = GraphQLFloat;
|
|
587
714
|
break;
|
|
588
715
|
case 'string':
|
|
589
|
-
this._types[id] = this._buildString(schema,
|
|
716
|
+
this._types[id] = this._buildString(schema, asInput);
|
|
590
717
|
break;
|
|
591
718
|
}
|
|
592
719
|
return this._types[id];
|
|
593
720
|
}
|
|
594
|
-
_buildArray(schema,
|
|
721
|
+
_buildArray(schema, parentName = '') {
|
|
595
722
|
const itemRef = schema.items.$ref;
|
|
596
|
-
return new GraphQLList(new GraphQLNonNull(this._getReference(itemRef,
|
|
723
|
+
return new GraphQLList(new GraphQLNonNull(this._getReference(itemRef, pascalCase(parentName + schema.title))));
|
|
597
724
|
}
|
|
598
|
-
_buildObject(id, schema,
|
|
599
|
-
const fields = this._buildObjectFields(id, schema
|
|
725
|
+
_buildObject(id, schema, parentName = '') {
|
|
726
|
+
const fields = this._buildObjectFields(id, schema);
|
|
600
727
|
return new GraphQLObjectType({
|
|
601
728
|
name: pascalCase(parentName + schema.title),
|
|
602
729
|
fields
|
|
603
730
|
});
|
|
604
731
|
}
|
|
605
|
-
_buildObjectFields(id, schema,
|
|
732
|
+
_buildObjectFields(id, schema, model) {
|
|
733
|
+
const definitions = this._getDefinitions();
|
|
606
734
|
const required = schema.required ?? [];
|
|
607
735
|
const fields = model ? {
|
|
608
736
|
id: {
|
|
@@ -619,7 +747,7 @@ export class SchemaBuilder {
|
|
|
619
747
|
if (fieldRef == null) {
|
|
620
748
|
throw new Error(`Missing ref for field ${key} of object ${id}`);
|
|
621
749
|
}
|
|
622
|
-
const type = this._getReference(fieldRef,
|
|
750
|
+
const type = this._getReference(fieldRef, schema.title ?? '');
|
|
623
751
|
fields[key] = {
|
|
624
752
|
type: required.includes(key) ? new GraphQLNonNull(type) : type
|
|
625
753
|
};
|
|
@@ -633,9 +761,9 @@ export class SchemaBuilder {
|
|
|
633
761
|
relationModelID = null;
|
|
634
762
|
relationType = definitions.documentInterface;
|
|
635
763
|
} else {
|
|
636
|
-
const relationID =
|
|
637
|
-
relationModelID = (relationID.isLocal ? relationID.toGlobal(
|
|
638
|
-
relationType = this._buildDocument(relationModelID
|
|
764
|
+
const relationID = DocumentModelID.fromString(relationModel);
|
|
765
|
+
relationModelID = (relationID.isLocal ? relationID.toGlobal(DocumentModelID.fromString(id)) : relationID).toString();
|
|
766
|
+
relationType = this._buildDocument(relationModelID);
|
|
639
767
|
}
|
|
640
768
|
if (isList(type)) {
|
|
641
769
|
// TODO: add suport for filters?
|
|
@@ -669,20 +797,21 @@ export class SchemaBuilder {
|
|
|
669
797
|
}
|
|
670
798
|
return fields;
|
|
671
799
|
}
|
|
672
|
-
_buildString(schema,
|
|
800
|
+
_buildString(schema, asInput) {
|
|
673
801
|
if (schema.enum != null) {
|
|
674
802
|
return this._buildEnumString(schema);
|
|
675
803
|
}
|
|
676
804
|
if (schema.format != null) {
|
|
677
805
|
return this._buildFormatString(schema);
|
|
678
806
|
}
|
|
679
|
-
return this._buildCustomString(schema,
|
|
807
|
+
return this._buildCustomString(schema, asInput);
|
|
680
808
|
}
|
|
681
|
-
_buildCustomString(schema,
|
|
809
|
+
_buildCustomString(schema, asInput) {
|
|
682
810
|
if (schema.title == null) {
|
|
683
811
|
// Plain string type
|
|
684
812
|
return GraphQLString;
|
|
685
813
|
}
|
|
814
|
+
const definitions = this._getDefinitions();
|
|
686
815
|
const title = schema.title.toLowerCase();
|
|
687
816
|
if (title === 'attachmentid') {
|
|
688
817
|
return asInput ? GraphQLID : definitions.attachmentObject;
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEnD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,GAAG,UAAU,CAEvF"}
|
package/lib/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/graphql",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "see LICENSE.md",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
],
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@enkaku/codec": "^0.11.0",
|
|
18
19
|
"change-case": "^5.4.4",
|
|
19
20
|
"graphql": "^16.9.0",
|
|
20
21
|
"graphql-relay": "^0.10.2",
|
|
21
|
-
"graphql-scalars": "^1.
|
|
22
|
-
"multiformats": "^13.3.
|
|
23
|
-
"@kubun/id": "^0.
|
|
24
|
-
"@kubun/protocol": "^0.
|
|
22
|
+
"graphql-scalars": "^1.24.2",
|
|
23
|
+
"multiformats": "^13.3.2",
|
|
24
|
+
"@kubun/id": "^0.2.0",
|
|
25
|
+
"@kubun/protocol": "^0.2.2"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"json-schema-typed": "^8.0.1"
|