@kubun/graphql 0.10.0 → 0.11.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.
@@ -1 +1,42 @@
1
- import{AttachmentID as t,DocumentID as n}from"@kubun/id";import{GraphQLError as e,GraphQLScalarType as i,Kind as r}from"graphql";function a(n){if("string"!=typeof n)throw new e(`Invalid AttachmentID input: ${n}`);return t.fromString(n),n}export const GraphQLAttachmentID=new i({name:"AttachmentID",description:"A Kubun Attachment identifier",serialize:a,parseValue:a,parseLiteral(t){if(t.kind!==r.STRING)throw new e(`Can only validate strings as AttachmentID but got a: ${t.kind}`);return a(t.value)}});function o(t){if("string"!=typeof t)throw new e(`Invalid DocumentID input: ${t}`);return n.fromString(t),t}export const GraphQLDocID=new i({name:"DocumentID",description:"A Kubun Document identifier",serialize:o,parseValue:o,parseLiteral(t){if(t.kind!==r.STRING)throw new e(`Can only validate strings as DocumentID but got a: ${t.kind}`);return o(t.value)}});
1
+ import { AttachmentID, DocumentID } from '@kubun/id';
2
+ import { GraphQLError, GraphQLScalarType, Kind } from 'graphql';
3
+ function validateAttachmentID(input) {
4
+ if (typeof input !== 'string') {
5
+ throw new GraphQLError(`Invalid AttachmentID input: ${input}`);
6
+ }
7
+ // Throws if input is not a valid AttachmentID string
8
+ AttachmentID.fromString(input);
9
+ return input;
10
+ }
11
+ export const GraphQLAttachmentID = new GraphQLScalarType({
12
+ name: 'AttachmentID',
13
+ description: 'A Kubun Attachment identifier',
14
+ serialize: validateAttachmentID,
15
+ parseValue: validateAttachmentID,
16
+ parseLiteral (ast) {
17
+ if (ast.kind !== Kind.STRING) {
18
+ throw new GraphQLError(`Can only validate strings as AttachmentID but got a: ${ast.kind}`);
19
+ }
20
+ return validateAttachmentID(ast.value);
21
+ }
22
+ });
23
+ function validateDocID(input) {
24
+ if (typeof input !== 'string') {
25
+ throw new GraphQLError(`Invalid DocumentID input: ${input}`);
26
+ }
27
+ // Throws if input is not a valid DocumentID string
28
+ DocumentID.fromString(input);
29
+ return input;
30
+ }
31
+ export const GraphQLDocID = new GraphQLScalarType({
32
+ name: 'DocumentID',
33
+ description: 'A Kubun Document identifier',
34
+ serialize: validateDocID,
35
+ parseValue: validateDocID,
36
+ parseLiteral (ast) {
37
+ if (ast.kind !== Kind.STRING) {
38
+ throw new GraphQLError(`Can only validate strings as DocumentID but got a: ${ast.kind}`);
39
+ }
40
+ return validateDocID(ast.value);
41
+ }
42
+ });
package/lib/index.js CHANGED
@@ -1 +1,8 @@
1
- export{createReadContext}from"./context.js";export{GraphQLAttachmentID,GraphQLDocID}from"./identifiers.js";export{createSchema,SchemaBuilder}from"./schema.js";
1
+ // `PluginContextMap` must be re-exported from this entry point (not only
2
+ // declared in `./context.js`) so plugins' `declare module '@kubun/graphql'`
3
+ // augmentation merges against the exported interface. Removing it from this
4
+ // list silently breaks resolver typing (`TS2339: Property '<name>' does not
5
+ // exist on type 'Context'`).
6
+ export { createReadContext } from './context.js';
7
+ export { GraphQLAttachmentID, GraphQLDocID } from './identifiers.js';
8
+ export { createSchema, SchemaBuilder } from './schema.js';
package/lib/scalars.js CHANGED
@@ -1 +1,23 @@
1
- import{GraphQLError as t,GraphQLScalarType as e,Kind as n}from"graphql";function r(e){if("string"!=typeof e)throw new t(`Invalid URL input: expected string, got ${typeof e}`);try{return new URL(e).toString()}catch{throw new t(`Invalid URL: ${e}`)}}export const GraphQLURL=new e({name:"URL",description:"A field whose value conforms to the standard URL format as specified in RFC3986",serialize:r,parseValue:r,parseLiteral(e){if(e.kind!==n.STRING)throw new t(`Can only validate strings as URLs but got a: ${e.kind}`);return r(e.value)}});
1
+ import { GraphQLError, GraphQLScalarType, Kind } from 'graphql';
2
+ function validateURL(input) {
3
+ if (typeof input !== 'string') {
4
+ throw new GraphQLError(`Invalid URL input: expected string, got ${typeof input}`);
5
+ }
6
+ try {
7
+ return new URL(input).toString();
8
+ } catch {
9
+ throw new GraphQLError(`Invalid URL: ${input}`);
10
+ }
11
+ }
12
+ export const GraphQLURL = new GraphQLScalarType({
13
+ name: 'URL',
14
+ description: 'A field whose value conforms to the standard URL format as specified in RFC3986',
15
+ serialize: validateURL,
16
+ parseValue: validateURL,
17
+ parseLiteral (ast) {
18
+ if (ast.kind !== Kind.STRING) {
19
+ throw new GraphQLError(`Can only validate strings as URLs but got a: ${ast.kind}`);
20
+ }
21
+ return validateURL(ast.value);
22
+ }
23
+ });