@kubun/graphql 0.13.0 → 0.13.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.
@@ -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>;
@@ -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
  }
@@ -2439,6 +2443,11 @@ export class SchemaBuilder {
2439
2443
  if (fieldRef == null) {
2440
2444
  throw new Error(`Missing ref for field ${key} of object ${id}`);
2441
2445
  }
2446
+ const attachmentField = this._buildNestedAttachmentField(key, fieldRef);
2447
+ if (attachmentField != null) {
2448
+ fields[key] = attachmentField;
2449
+ continue;
2450
+ }
2442
2451
  const type = this._getReference(fieldRef, parentName);
2443
2452
  fields[key] = {
2444
2453
  type: required.includes(key) ? new GraphQLNonNull(type) : type
@@ -2446,6 +2455,24 @@ export class SchemaBuilder {
2446
2455
  }
2447
2456
  return fields;
2448
2457
  }
2458
+ // An attachmentid leaf nested inside an object is exposed as the AttachmentNode
2459
+ // object rather than a bare AttachmentID scalar, so state/mimeType/contentLength
2460
+ // resolve — mirroring the top-level attachment convenience fields. Always
2461
+ // nullable (like the top-level fields): the value may be absent, e.g. an
2462
+ // attachment not yet imported. Returns null for non-attachment fields.
2463
+ _buildNestedAttachmentField(key, fieldRef) {
2464
+ const refSchema = this._getReferenceSchema(getReferenceID(fieldRef));
2465
+ if (!isAttachmentIDString(refSchema)) {
2466
+ return null;
2467
+ }
2468
+ return {
2469
+ type: this._getDefinitions().attachmentObject,
2470
+ resolve: (source)=>{
2471
+ const value = source[key];
2472
+ return value ? AttachmentID.fromString(value) : null;
2473
+ }
2474
+ };
2475
+ }
2449
2476
  _buildRelationFields(fields, fieldName, relation) {
2450
2477
  if (relation.isList) {
2451
2478
  // 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.13.0",
3
+ "version": "0.13.1",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -22,20 +22,21 @@
22
22
  "change-case": "^5.4.4",
23
23
  "graphql": "^16.14.2",
24
24
  "graphql-relay": "^0.10.2",
25
- "graphql-scalars": "^1.26.0",
25
+ "graphql-scalars": "^2.0.0",
26
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"
27
+ "@kubun/hlc": "^0.13.0",
28
+ "@kubun/logger": "^0.13.0",
29
+ "@kubun/id": "^0.13.0",
30
+ "@kubun/protocol": "^0.13.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@kokuin/capability": "^0.2.2",
34
- "@kokuin/token": "^0.4.0",
35
- "@kubun/store-graph": "^0.13.0",
36
- "@kubun/db-better-sqlite": "^0.12.1",
37
- "@kubun/db": "^0.12.1",
38
- "@kubun/test-utils": "^0.12.0"
33
+ "@kokuin/capability": "^0.3.0",
34
+ "@kokuin/token": "^0.5.0",
35
+ "@kubun/db": "^0.13.0",
36
+ "@kubun/db-better-sqlite": "^0.13.0",
37
+ "@kubun/scalars": "^0.13.0",
38
+ "@kubun/store-graph": "^0.13.1",
39
+ "@kubun/test-utils": "^0.13.0"
39
40
  },
40
41
  "publishConfig": {
41
42
  "access": "public"