@pothos/plugin-relay
Advanced tools
Comparing version 3.43.1 to 3.44.0
# Change Log | ||
## 3.44.0 | ||
### Minor Changes | ||
- 96ba1822: Improve validation for global IDs | ||
## 3.43.1 | ||
@@ -4,0 +10,0 @@ |
@@ -22,3 +22,3 @@ import { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, FieldRequiredness, InputFieldMap, InputFieldRef, InputFieldsFromShape, InputShapeFromFields, InputShapeFromTypeParam, inputShapeKey, InterfaceParam, NormalizeArgs, ObjectFieldsShape, ObjectFieldThunk, ObjectParam, OutputShape, OutputType, ParentShape, Resolver, SchemaTypes, ShapeFromTypeParam } from '@pothos/core'; | ||
unknown | ||
]> extends PartialTypes['DefaultEdgesNullability'] ? DefaultEdgesNullability : PartialTypes['DefaultEdgesNullability'] & FieldNullability<[unknown]>; | ||
]> extends PartialTypes['DefaultEdgesNullability'] ? DefaultEdgesNullability : FieldNullability<[unknown]> & PartialTypes['DefaultEdgesNullability']; | ||
DefaultNodeNullability: boolean extends PartialTypes['DefaultNodeNullability'] ? false : PartialTypes['DefaultNodeNullability'] & boolean; | ||
@@ -79,10 +79,10 @@ } | ||
nodeList: <Args extends InputFieldMap, ResolveShape>(options: NodeListFieldOptions<Types, ParentShape, Args, ResolveShape, Kind>) => FieldRef<readonly unknown[]>; | ||
connection: <Type extends OutputType<Types>, Args extends InputFieldMap, Nullable extends boolean, ResolveShape, ResolveReturnShape, EdgeNullability extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullability extends boolean = Types['DefaultNodeNullability'], ConnectionInterfaces extends InterfaceParam<Types>[] = [], EdgeInterfaces extends InterfaceParam<Types>[] = [], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>>(options: FieldOptionsFromKind<Types, ParentShape, Type, Nullable, (InputFieldMap extends Args ? {} : Args) & InputFieldsFromShape<DefaultConnectionArguments>, Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ConnectionFieldOptions<Types, FieldOptions extends { | ||
connection: <Type extends OutputType<Types>, Args extends InputFieldMap, Nullable extends boolean, ResolveShape, ResolveReturnShape, EdgeNullability extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullability extends boolean = Types['DefaultNodeNullability'], ConnectionInterfaces extends InterfaceParam<Types>[] = [], EdgeInterfaces extends InterfaceParam<Types>[] = [], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>>(options: FieldOptionsFromKind<Types, ParentShape, Type, Nullable, InputFieldsFromShape<DefaultConnectionArguments> & (InputFieldMap extends Args ? {} : Args), Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ConnectionFieldOptions<Types, FieldOptions extends { | ||
resolve?: (parent: infer P, ...args: any[]) => unknown; | ||
} ? P : unknown extends ResolveShape ? ParentShape : ResolveShape, Type, Nullable, EdgeNullability, NodeNullability, Args, ResolveReturnShape, ConnectionResult> & Omit<FieldOptions, 'args' | 'resolve' | 'type'> : never, ...args: NormalizeArgs<[ | ||
connectionOptions: ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability, ConnectionResult>> | Omit<ConnectionObjectOptions<Types, Type, EdgeNullability, NodeNullability, ResolveReturnShape, ConnectionInterfaces>, 'edgesNullable'>, | ||
edgeOptions: ObjectRef<{ | ||
edgeOptions: ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape, EdgeInterfaces> | ObjectRef<{ | ||
cursor: string; | ||
node?: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}> | ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape, EdgeInterfaces> | ||
}> | ||
], 0>) => FieldRef<ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>>; | ||
@@ -95,3 +95,3 @@ } | ||
nodeNullable?: NodeNullability; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args> & DefaultConnectionArguments, Types['Context'], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult>, ResolveReturnShape>; | ||
resolve: Resolver<ParentShape, DefaultConnectionArguments & InputShapeFromFields<Args>, Types['Context'], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult>, ResolveReturnShape>; | ||
} | ||
@@ -98,0 +98,0 @@ interface ConnectionObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Resolved, Interfaces extends InterfaceParam<Types>[] = [], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> extends ObjectTypeWithInterfaceOptions<Types, ConnectionShapeFromResolve<Types, Type, false, EdgeNullability, NodeNullability, Resolved, ConnectionResult>, Interfaces> { |
@@ -5,3 +5,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
idFieldName?: string; | ||
idFieldOptions?: Partial<Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, 'ID', boolean, {}, PageInfoShape>, 'args' | 'resolve' | 'type' | 'nullable'>>; | ||
idFieldOptions?: Partial<Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, 'ID', boolean, {}, PageInfoShape>, 'args' | 'nullable' | 'resolve' | 'type'>>; | ||
clientMutationId?: 'omit' | 'optional' | 'required'; | ||
@@ -57,3 +57,3 @@ cursorType?: 'ID' | 'String'; | ||
ObjectRef<{}> | ||
], Types['DefaultEdgesNullability'], {}, unknown[]>, 'args' | 'resolve' | 'nullable' | 'type'> & { | ||
], Types['DefaultEdgesNullability'], {}, unknown[]>, 'args' | 'nullable' | 'resolve' | 'type'> & { | ||
nullable?: Types['DefaultEdgesNullability']; | ||
@@ -83,3 +83,3 @@ }; | ||
defaultConnectionFieldOptions?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, OutputRef<ConnectionShape<Types, unknown, false, true, true>>, boolean, InputFieldsFromShape<DefaultConnectionArguments>, ConnectionShape<Types, unknown, false, true, true>>, 'args' | 'resolve' | 'type'>; | ||
nodesOnConnection?: boolean | Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, [ | ||
nodesOnConnection?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, [ | ||
ObjectRef<{}> | ||
@@ -89,3 +89,3 @@ ], { | ||
items: Types['DefaultNodeNullability']; | ||
}, {}, GlobalIDShape<Types> | string>, 'args' | 'nullable' | 'resolve' | 'type'>; | ||
}, {}, GlobalIDShape<Types> | string>, 'args' | 'nullable' | 'resolve' | 'type'> | boolean; | ||
}>; | ||
@@ -116,3 +116,3 @@ export interface DefaultEdgesNullability { | ||
} | ||
export type ConnectionShape<Types extends SchemaTypes, T, Nullable, EdgesNullable extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullable extends boolean = Types['DefaultNodeNullability'], ConnectionResult extends ConnectionResultShape<Types, T, EdgesNullable, NodeNullable> = ConnectionResultShape<Types, T, EdgesNullable, NodeNullable>> = (Nullable extends false ? never : null | undefined) | (Types['Connection'] & ConnectionResult); | ||
export type ConnectionShape<Types extends SchemaTypes, T, Nullable, EdgesNullable extends FieldNullability<[unknown]> = Types['DefaultEdgesNullability'], NodeNullable extends boolean = Types['DefaultNodeNullability'], ConnectionResult extends ConnectionResultShape<Types, T, EdgesNullable, NodeNullable> = ConnectionResultShape<Types, T, EdgesNullable, NodeNullable>> = (Nullable extends false ? never : null | undefined) | (ConnectionResult & Types['Connection']); | ||
export type ConnectionShapeFromBaseShape<Types extends SchemaTypes, Shape, Nullable extends boolean> = ConnectionShape<Types, Shape, Nullable>; | ||
@@ -119,0 +119,0 @@ export type ConnectionShapeForType<Types extends SchemaTypes, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>> = ConnectionShape<Types, ShapeFromTypeParam<Types, Type, false>, Nullable, EdgeNullability, NodeNullability, ConnectionResult>; |
@@ -24,5 +24,5 @@ import { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, FieldRequiredness, InputFieldMap, InputFieldRef, InputFieldsFromShape, InputShapeFromFields, InputShapeFromTypeParam, inputShapeKey, InterfaceParam, NormalizeArgs, ObjectFieldsShape, ObjectFieldThunk, ObjectParam, OutputShape, OutputType, ParentShape, Resolver, SchemaTypes, ShapeFromTypeParam } from '@pothos/core'; | ||
unknown | ||
]> extends PartialTypes["DefaultEdgesNullability"] ? DefaultEdgesNullability : PartialTypes["DefaultEdgesNullability"] & FieldNullability<[ | ||
]> extends PartialTypes["DefaultEdgesNullability"] ? DefaultEdgesNullability : FieldNullability<[ | ||
unknown | ||
]>; | ||
]> & PartialTypes["DefaultEdgesNullability"]; | ||
DefaultNodeNullability: boolean extends PartialTypes["DefaultNodeNullability"] ? false : PartialTypes["DefaultNodeNullability"] & boolean; | ||
@@ -102,10 +102,10 @@ } | ||
], EdgeInterfaces extends InterfaceParam<Types>[] = [ | ||
], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>>(options: FieldOptionsFromKind<Types, ParentShape, Type, Nullable, (InputFieldMap extends Args ? {} : Args) & InputFieldsFromShape<DefaultConnectionArguments>, Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ConnectionFieldOptions<Types, FieldOptions extends { | ||
], ConnectionResult extends ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability> = ConnectionResultShape<Types, ShapeFromTypeParam<Types, Type, false>, EdgeNullability, NodeNullability>>(options: FieldOptionsFromKind<Types, ParentShape, Type, Nullable, InputFieldsFromShape<DefaultConnectionArguments> & (InputFieldMap extends Args ? {} : Args), Kind, ResolveShape, ResolveReturnShape> extends infer FieldOptions ? ConnectionFieldOptions<Types, FieldOptions extends { | ||
resolve?: (parent: infer P, ...args: any[]) => unknown; | ||
} ? P : unknown extends ResolveShape ? ParentShape : ResolveShape, Type, Nullable, EdgeNullability, NodeNullability, Args, ResolveReturnShape, ConnectionResult> & Omit<FieldOptions, "args" | "resolve" | "type"> : never, ...args: NormalizeArgs<[ | ||
connectionOptions: ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability, ConnectionResult>> | Omit<ConnectionObjectOptions<Types, Type, EdgeNullability, NodeNullability, ResolveReturnShape, ConnectionInterfaces>, "edgesNullable">, | ||
edgeOptions: ObjectRef<{ | ||
edgeOptions: ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape, EdgeInterfaces> | ObjectRef<{ | ||
cursor: string; | ||
node?: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}> | ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape, EdgeInterfaces> | ||
}> | ||
], 0>) => FieldRef<ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>>; | ||
@@ -120,3 +120,3 @@ } | ||
nodeNullable?: NodeNullability; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args> & DefaultConnectionArguments, Types["Context"], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult>, ResolveReturnShape>; | ||
resolve: Resolver<ParentShape, DefaultConnectionArguments & InputShapeFromFields<Args>, Types["Context"], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability, ConnectionResult>, ResolveReturnShape>; | ||
} | ||
@@ -123,0 +123,0 @@ interface ConnectionObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, EdgeNullability extends FieldNullability<[ |
@@ -5,3 +5,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
idFieldName?: string; | ||
idFieldOptions?: Partial<Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, "ID", boolean, {}, PageInfoShape>, "args" | "resolve" | "type" | "nullable">>; | ||
idFieldOptions?: Partial<Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, "ID", boolean, {}, PageInfoShape>, "args" | "nullable" | "resolve" | "type">>; | ||
clientMutationId?: "omit" | "optional" | "required"; | ||
@@ -59,3 +59,3 @@ cursorType?: "ID" | "String"; | ||
ObjectRef<{}> | ||
], Types["DefaultEdgesNullability"], {}, unknown[]>, "args" | "resolve" | "nullable" | "type"> & { | ||
], Types["DefaultEdgesNullability"], {}, unknown[]>, "args" | "nullable" | "resolve" | "type"> & { | ||
nullable?: Types["DefaultEdgesNullability"]; | ||
@@ -85,3 +85,3 @@ }; | ||
defaultConnectionFieldOptions?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, OutputRef<ConnectionShape<Types, unknown, false, true, true>>, boolean, InputFieldsFromShape<DefaultConnectionArguments>, ConnectionShape<Types, unknown, false, true, true>>, "args" | "resolve" | "type">; | ||
nodesOnConnection?: boolean | Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, [ | ||
nodesOnConnection?: Omit<PothosSchemaTypes.ObjectFieldOptions<Types, {}, [ | ||
ObjectRef<{}> | ||
@@ -91,3 +91,3 @@ ], { | ||
items: Types["DefaultNodeNullability"]; | ||
}, {}, GlobalIDShape<Types> | string>, "args" | "nullable" | "resolve" | "type">; | ||
}, {}, GlobalIDShape<Types> | string>, "args" | "nullable" | "resolve" | "type"> | boolean; | ||
}>; | ||
@@ -124,3 +124,3 @@ export interface DefaultEdgesNullability { | ||
unknown | ||
]> = Types["DefaultEdgesNullability"], NodeNullable extends boolean = Types["DefaultNodeNullability"], ConnectionResult extends ConnectionResultShape<Types, T, EdgesNullable, NodeNullable> = ConnectionResultShape<Types, T, EdgesNullable, NodeNullable>> = (Nullable extends false ? never : null | undefined) | (Types["Connection"] & ConnectionResult); | ||
]> = Types["DefaultEdgesNullability"], NodeNullable extends boolean = Types["DefaultNodeNullability"], ConnectionResult extends ConnectionResultShape<Types, T, EdgesNullable, NodeNullable> = ConnectionResultShape<Types, T, EdgesNullable, NodeNullable>> = (Nullable extends false ? never : null | undefined) | (ConnectionResult & Types["Connection"]); | ||
export type ConnectionShapeFromBaseShape<Types extends SchemaTypes, Shape, Nullable extends boolean> = ConnectionShape<Types, Shape, Nullable>; | ||
@@ -127,0 +127,0 @@ export type ConnectionShapeForType<Types extends SchemaTypes, Type extends OutputType<Types>, Nullable extends boolean, EdgeNullability extends FieldNullability<[ |
@@ -5,6 +5,13 @@ import { decodeBase64, encodeBase64, PothosValidationError } from '@pothos/core'; | ||
} | ||
const typenameRegex = /^[A-Z_a-z]\w*$/; | ||
export function decodeGlobalID(globalID) { | ||
const decoded = decodeBase64(globalID).split(":"); | ||
let decoded; | ||
try { | ||
decoded = decodeBase64(globalID).split(":"); | ||
} | ||
catch (error) { | ||
throw error instanceof PothosValidationError ? new PothosValidationError(`Invalid global ID: ${globalID}`) : error; | ||
} | ||
const [typename, id] = decoded; | ||
if (!typename || !id) { | ||
if (!typename || !id || !typenameRegex.test(typename)) { | ||
throw new PothosValidationError(`Invalid global ID: ${globalID}`); | ||
@@ -11,0 +18,0 @@ } |
@@ -23,6 +23,12 @@ "use strict"; | ||
} | ||
const typenameRegex = /^[A-Z_a-z]\w*$/; | ||
function decodeGlobalID(globalID) { | ||
const decoded = (0, _core.decodeBase64)(globalID).split(':'); | ||
let decoded; | ||
try { | ||
decoded = (0, _core.decodeBase64)(globalID).split(':'); | ||
} catch (error) { | ||
throw error instanceof _core.PothosValidationError ? new _core.PothosValidationError(`Invalid global ID: ${globalID}`) : error; | ||
} | ||
const [typename, id] = decoded; | ||
if (!typename || !id) { | ||
if (!typename || !id || !typenameRegex.test(typename)) { | ||
throw new _core.PothosValidationError(`Invalid global ID: ${globalID}`); | ||
@@ -29,0 +35,0 @@ } |
{ | ||
"name": "@pothos/plugin-relay", | ||
"version": "3.43.1", | ||
"version": "3.44.0", | ||
"description": "A Pothos plugin for adding relay style connections, nodes, and cursor based pagination to your GraphQL schema", | ||
@@ -45,6 +45,6 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"graphql": "16.7.1", | ||
"graphql": "16.8.0", | ||
"graphql-subscriptions": "^2.0.0", | ||
"graphql-tag": "^2.12.6", | ||
"@pothos/core": "3.33.0", | ||
"@pothos/core": "3.36.0", | ||
"@pothos/plugin-complexity": "3.13.0", | ||
@@ -51,0 +51,0 @@ "@pothos/test-utils": "1.4.8" |
@@ -72,3 +72,3 @@ import { | ||
? DefaultEdgesNullability | ||
: PartialTypes['DefaultEdgesNullability'] & FieldNullability<[unknown]>; | ||
: FieldNullability<[unknown]> & PartialTypes['DefaultEdgesNullability']; | ||
DefaultNodeNullability: boolean extends PartialTypes['DefaultNodeNullability'] | ||
@@ -287,4 +287,4 @@ ? false | ||
Nullable, | ||
(InputFieldMap extends Args ? {} : Args) & | ||
InputFieldsFromShape<DefaultConnectionArguments>, | ||
InputFieldsFromShape<DefaultConnectionArguments> & | ||
(InputFieldMap extends Args ? {} : Args), | ||
Kind, | ||
@@ -336,6 +336,2 @@ ResolveShape, | ||
edgeOptions: | ||
| ObjectRef<{ | ||
cursor: string; | ||
node?: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}> | ||
| ConnectionEdgeObjectOptions< | ||
@@ -347,3 +343,7 @@ Types, | ||
EdgeInterfaces | ||
>, | ||
> | ||
| ObjectRef<{ | ||
cursor: string; | ||
node?: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}>, | ||
], | ||
@@ -384,3 +384,3 @@ 0 | ||
ParentShape, | ||
InputShapeFromFields<Args> & DefaultConnectionArguments, | ||
DefaultConnectionArguments & InputShapeFromFields<Args>, | ||
Types['Context'], | ||
@@ -387,0 +387,0 @@ ConnectionShapeForType< |
@@ -32,3 +32,3 @@ import './global-types'; | ||
inputField.extensions?.relayGlobalIDAlwaysParse ?? | ||
false) as boolean | { typename: string; parseId: (id: string, ctx: object) => unknown }[]; | ||
false) as { typename: string; parseId: (id: string, ctx: object) => unknown }[] | boolean; | ||
} | ||
@@ -60,4 +60,4 @@ | ||
return (inputField.extensions?.relayGlobalIDFor ?? true) as | ||
| true | ||
| { typename: string; parseId: (id: string, ctx: object) => unknown }[]; | ||
| { typename: string; parseId: (id: string, ctx: object) => unknown }[] | ||
| true; | ||
} | ||
@@ -64,0 +64,0 @@ |
@@ -7,2 +7,3 @@ import { ObjectRef } from '@pothos/core'; | ||
[relayIDShapeKey]!: IDShape; | ||
parseId: ((id: string, ctx: object) => IDShape) | undefined; | ||
@@ -9,0 +10,0 @@ |
@@ -38,3 +38,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
PothosSchemaTypes.ObjectFieldOptions<Types, {}, 'ID', boolean, {}, PageInfoShape>, | ||
'args' | 'resolve' | 'type' | 'nullable' | ||
'args' | 'nullable' | 'resolve' | 'type' | ||
> | ||
@@ -156,3 +156,3 @@ >; | ||
>, | ||
'args' | 'resolve' | 'nullable' | 'type' | ||
'args' | 'nullable' | 'resolve' | 'type' | ||
> & { | ||
@@ -252,3 +252,2 @@ nullable?: Types['DefaultEdgesNullability']; | ||
nodesOnConnection?: | ||
| boolean | ||
| Omit< | ||
@@ -267,3 +266,4 @@ PothosSchemaTypes.ObjectFieldOptions< | ||
'args' | 'nullable' | 'resolve' | 'type' | ||
>; | ||
> | ||
| boolean; | ||
}>; | ||
@@ -327,3 +327,3 @@ | ||
> = ConnectionResultShape<Types, T, EdgesNullable, NodeNullable>, | ||
> = (Nullable extends false ? never : null | undefined) | (Types['Connection'] & ConnectionResult); | ||
> = (Nullable extends false ? never : null | undefined) | (ConnectionResult & Types['Connection']); | ||
@@ -330,0 +330,0 @@ export type ConnectionShapeFromBaseShape< |
@@ -7,7 +7,17 @@ import { decodeBase64, encodeBase64, PothosValidationError } from '@pothos/core'; | ||
const typenameRegex = /^[A-Z_a-z]\w*$/; | ||
export function decodeGlobalID(globalID: string) { | ||
const decoded = decodeBase64(globalID).split(':'); | ||
let decoded; | ||
try { | ||
decoded = decodeBase64(globalID).split(':'); | ||
} catch (error) { | ||
throw error instanceof PothosValidationError | ||
? new PothosValidationError(`Invalid global ID: ${globalID}`) | ||
: error; | ||
} | ||
const [typename, id] = decoded; | ||
if (!typename || !id) { | ||
if (!typename || !id || !typenameRegex.test(typename)) { | ||
throw new PothosValidationError(`Invalid global ID: ${globalID}`); | ||
@@ -14,0 +24,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
426264
5545