@kubun/graphql 0.13.0 → 0.14.0
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 +1 -0
- package/lib/identifiers.js +23 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/schema.d.ts +1 -0
- package/lib/schema.js +31 -3
- package/package.json +14 -13
package/lib/identifiers.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GraphQLScalarType } from 'graphql';
|
|
2
2
|
export declare const GraphQLAttachmentID: GraphQLScalarType<string, string>;
|
|
3
|
+
export declare const GraphQLCredentialEntryID: GraphQLScalarType<string, string>;
|
|
3
4
|
export declare const GraphQLDocID: GraphQLScalarType<string, string>;
|
package/lib/identifiers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AttachmentID, DocumentID } from '@kubun/id';
|
|
1
|
+
import { AttachmentID, CredentialEntryID, DocumentID } from '@kubun/id';
|
|
2
2
|
import { GraphQLError, GraphQLScalarType, Kind } from 'graphql';
|
|
3
3
|
function validateAttachmentID(input) {
|
|
4
4
|
if (typeof input !== 'string') {
|
|
@@ -20,6 +20,28 @@ export const GraphQLAttachmentID = new GraphQLScalarType({
|
|
|
20
20
|
return validateAttachmentID(ast.value);
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
+
function validateCredentialEntryID(input) {
|
|
24
|
+
if (typeof input !== 'string') {
|
|
25
|
+
throw new GraphQLError(`Invalid CredentialEntryID input: ${input}`);
|
|
26
|
+
}
|
|
27
|
+
// The whole check. Every Kubun id matches the scalar's pattern, so a document
|
|
28
|
+
// id or a credential KEY id would otherwise reach a resolver that expects an
|
|
29
|
+
// entry and miss with a message about absence rather than about type.
|
|
30
|
+
CredentialEntryID.fromString(input);
|
|
31
|
+
return input;
|
|
32
|
+
}
|
|
33
|
+
export const GraphQLCredentialEntryID = new GraphQLScalarType({
|
|
34
|
+
name: 'CredentialEntryID',
|
|
35
|
+
description: 'A Kubun Credential Entry identifier',
|
|
36
|
+
serialize: validateCredentialEntryID,
|
|
37
|
+
parseValue: validateCredentialEntryID,
|
|
38
|
+
parseLiteral (ast) {
|
|
39
|
+
if (ast.kind !== Kind.STRING) {
|
|
40
|
+
throw new GraphQLError(`Can only validate strings as CredentialEntryID but got a: ${ast.kind}`);
|
|
41
|
+
}
|
|
42
|
+
return validateCredentialEntryID(ast.value);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
23
45
|
function validateDocID(input) {
|
|
24
46
|
if (typeof input !== 'string') {
|
|
25
47
|
throw new GraphQLError(`Invalid DocumentID input: ${input}`);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { AccessWarning, AggregateScope, ComplexityStats, Context, CreateMutationParams, DocumentEventEmitter, DocumentSavedEvent, MutationContext, PluginContextMap, QueryContext, ReadContextDB, ReadContextParams, ReadOnlyContext, RemoveMutationParams, ScopedConnection, SetDocumentAccessOverrideParams, SetModelAccessDefaultsParams, SetMutationParams, SubscriptionContext, UpdateMutationParams, } from './context.js';
|
|
2
2
|
export { createReadContext } from './context.js';
|
|
3
|
-
export { GraphQLAttachmentID, GraphQLDocID } from './identifiers.js';
|
|
3
|
+
export { GraphQLAttachmentID, GraphQLCredentialEntryID, GraphQLDocID, } from './identifiers.js';
|
|
4
4
|
export type { ExtensionResolvers, SchemaBuilderParams, SharedDefinitions, } from './schema.js';
|
|
5
5
|
export { createSchema, SchemaBuilder } from './schema.js';
|
|
6
6
|
export type * from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
// list silently breaks resolver typing (`TS2339: Property '<name>' does not
|
|
5
5
|
// exist on type 'Context'`).
|
|
6
6
|
export { createReadContext } from './context.js';
|
|
7
|
-
export { GraphQLAttachmentID, GraphQLDocID } from './identifiers.js';
|
|
7
|
+
export { GraphQLAttachmentID, GraphQLCredentialEntryID, GraphQLDocID } from './identifiers.js';
|
|
8
8
|
export { createSchema, SchemaBuilder } from './schema.js';
|
package/lib/schema.d.ts
CHANGED
|
@@ -194,6 +194,7 @@ export declare class SchemaBuilder {
|
|
|
194
194
|
_buildArray(schema: ArrayModel, parentName?: string): GraphQLList<GraphQLNonNull<GraphQLOutputType>>;
|
|
195
195
|
_buildObject(id: string, schema: ObjectModel, parentName?: string): GraphQLObjectType;
|
|
196
196
|
_buildObjectFields(id: string, schema: DocumentModelSchema | ObjectModel, parentName?: string): GraphQLFieldConfigMap<Record<string, unknown>, Context>;
|
|
197
|
+
_buildNestedAttachmentField(key: string, fieldRef: string): GraphQLFieldConfig<Record<string, unknown>, Context> | null;
|
|
197
198
|
_buildRelationFields(fields: GraphQLFieldConfigMap<DocumentNode, Context>, fieldName: string, relation: RelationField): void;
|
|
198
199
|
_buildRelationSubscriptions(fields: GraphQLFieldConfigMap<unknown, Context>, modelID: string, fieldName: string, relation: RelationField): void;
|
|
199
200
|
_buildString(schema: StringModel, parentName: string): GraphQLEnumType | GraphQLObjectType | GraphQLScalarType;
|
package/lib/schema.js
CHANGED
|
@@ -4,7 +4,7 @@ import { pascalCase } from 'change-case';
|
|
|
4
4
|
import { extendSchema, GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLString, isEnumType, isListType, isNonNullType, isObjectType, isScalarType, Kind, parse as parseGraphQL } from 'graphql';
|
|
5
5
|
import { connectionArgs, connectionDefinitions, mutationWithClientMutationId, nodeDefinitions } from 'graphql-relay';
|
|
6
6
|
import { GraphQLDateTimeISO, GraphQLDID, GraphQLDuration, GraphQLEmailAddress, GraphQLJSON, GraphQLJSONObject } from 'graphql-scalars';
|
|
7
|
-
import { GraphQLAttachmentID, GraphQLDocID } from './identifiers.js';
|
|
7
|
+
import { GraphQLAttachmentID, GraphQLCredentialEntryID, GraphQLDocID } from './identifiers.js';
|
|
8
8
|
import { GraphQLURL } from './scalars.js';
|
|
9
9
|
import { getUniqueDocValue, validateAccessIdentifiers } from './utils.js';
|
|
10
10
|
/**
|
|
@@ -44,9 +44,13 @@ const STRING_FORMATS = {
|
|
|
44
44
|
};
|
|
45
45
|
const STRING_TITLES = {
|
|
46
46
|
attachmentid: GraphQLAttachmentID,
|
|
47
|
+
credentialentryid: GraphQLCredentialEntryID,
|
|
47
48
|
did: GraphQLDID,
|
|
48
49
|
docid: GraphQLDocID
|
|
49
50
|
};
|
|
51
|
+
function isAttachmentIDString(schema) {
|
|
52
|
+
return schema.type === 'string' && schema.title?.toLowerCase() === 'attachmentid';
|
|
53
|
+
}
|
|
50
54
|
function getReferenceID(path) {
|
|
51
55
|
return path.slice(REFERENCE_PREFIX.length);
|
|
52
56
|
}
|
|
@@ -854,12 +858,13 @@ export class SchemaBuilder {
|
|
|
854
858
|
fields: queryFields
|
|
855
859
|
}),
|
|
856
860
|
// Ensure custom scalars stay reachable from the schema typeMap so plugin
|
|
857
|
-
// SDL extensions can reference them by name (URL, DID, DateTimeISO)
|
|
861
|
+
// SDL extensions can reference them by name (URL, DID, DateTimeISO, JSON)
|
|
858
862
|
// regardless of whether any model field happens to use them.
|
|
859
863
|
types: [
|
|
860
864
|
GraphQLURL,
|
|
861
865
|
GraphQLDID,
|
|
862
|
-
GraphQLDateTimeISO
|
|
866
|
+
GraphQLDateTimeISO,
|
|
867
|
+
GraphQLJSON
|
|
863
868
|
]
|
|
864
869
|
};
|
|
865
870
|
if (this._includeMutations) {
|
|
@@ -2439,6 +2444,11 @@ export class SchemaBuilder {
|
|
|
2439
2444
|
if (fieldRef == null) {
|
|
2440
2445
|
throw new Error(`Missing ref for field ${key} of object ${id}`);
|
|
2441
2446
|
}
|
|
2447
|
+
const attachmentField = this._buildNestedAttachmentField(key, fieldRef);
|
|
2448
|
+
if (attachmentField != null) {
|
|
2449
|
+
fields[key] = attachmentField;
|
|
2450
|
+
continue;
|
|
2451
|
+
}
|
|
2442
2452
|
const type = this._getReference(fieldRef, parentName);
|
|
2443
2453
|
fields[key] = {
|
|
2444
2454
|
type: required.includes(key) ? new GraphQLNonNull(type) : type
|
|
@@ -2446,6 +2456,24 @@ export class SchemaBuilder {
|
|
|
2446
2456
|
}
|
|
2447
2457
|
return fields;
|
|
2448
2458
|
}
|
|
2459
|
+
// An attachmentid leaf nested inside an object is exposed as the AttachmentNode
|
|
2460
|
+
// object rather than a bare AttachmentID scalar, so state/mimeType/contentLength
|
|
2461
|
+
// resolve — mirroring the top-level attachment convenience fields. Always
|
|
2462
|
+
// nullable (like the top-level fields): the value may be absent, e.g. an
|
|
2463
|
+
// attachment not yet imported. Returns null for non-attachment fields.
|
|
2464
|
+
_buildNestedAttachmentField(key, fieldRef) {
|
|
2465
|
+
const refSchema = this._getReferenceSchema(getReferenceID(fieldRef));
|
|
2466
|
+
if (!isAttachmentIDString(refSchema)) {
|
|
2467
|
+
return null;
|
|
2468
|
+
}
|
|
2469
|
+
return {
|
|
2470
|
+
type: this._getDefinitions().attachmentObject,
|
|
2471
|
+
resolve: (source)=>{
|
|
2472
|
+
const value = source[key];
|
|
2473
|
+
return value ? AttachmentID.fromString(value) : null;
|
|
2474
|
+
}
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2449
2477
|
_buildRelationFields(fields, fieldName, relation) {
|
|
2450
2478
|
if (relation.isList) {
|
|
2451
2479
|
// DB does not support matches for array containing values
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/graphql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"license": "see LICENSE.md",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"LICENSE.md"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@kubun/hlc": "^0.14.0",
|
|
19
|
+
"@kubun/id": "^0.14.0",
|
|
20
|
+
"@kubun/logger": "^0.14.0",
|
|
21
|
+
"@kubun/protocol": "^0.14.0",
|
|
18
22
|
"@sozai/async": "^0.2.1",
|
|
19
23
|
"@sozai/codec": "^0.4.0",
|
|
20
24
|
"@sozai/event": "^0.1.3",
|
|
@@ -22,20 +26,17 @@
|
|
|
22
26
|
"change-case": "^5.4.4",
|
|
23
27
|
"graphql": "^16.14.2",
|
|
24
28
|
"graphql-relay": "^0.10.2",
|
|
25
|
-
"graphql-scalars": "^
|
|
26
|
-
"multiformats": "^14.0.5"
|
|
27
|
-
"@kubun/logger": "^0.12.0",
|
|
28
|
-
"@kubun/hlc": "^0.12.0",
|
|
29
|
-
"@kubun/id": "^0.12.0",
|
|
30
|
-
"@kubun/protocol": "^0.13.0"
|
|
29
|
+
"graphql-scalars": "^2.0.0",
|
|
30
|
+
"multiformats": "^14.0.5"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@kokuin/capability": "^0.
|
|
34
|
-
"@kokuin/token": "^0.
|
|
35
|
-
"@kubun/
|
|
36
|
-
"@kubun/db-better-sqlite": "^0.
|
|
37
|
-
"@kubun/
|
|
38
|
-
"@kubun/
|
|
33
|
+
"@kokuin/capability": "^0.3.0",
|
|
34
|
+
"@kokuin/token": "^0.5.0",
|
|
35
|
+
"@kubun/db": "^0.14.0",
|
|
36
|
+
"@kubun/db-better-sqlite": "^0.14.0",
|
|
37
|
+
"@kubun/scalars": "^0.14.0",
|
|
38
|
+
"@kubun/store-graph": "^0.14.0",
|
|
39
|
+
"@kubun/test-utils": "^0.13.0"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public"
|