deno.land / x / pothos@release-1713397530 / packages / plugin-relay / utils / internal.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// @ts-nocheckimport { GraphQLResolveInfo } from 'https://cdn.skypack.dev/graphql?dts';import { PothosValidationError, SchemaTypes } from '../../core/index.ts';import { decodeGlobalID, encodeGlobalID } from './global-ids.ts';export function internalEncodeGlobalID<Types extends SchemaTypes>(builder: PothosSchemaTypes.SchemaBuilder<Types>, typename: string, id: bigint | number | string, ctx: object) { if (builder.options.relayOptions.encodeGlobalID) { return builder.options.relayOptions.encodeGlobalID(typename, id, ctx); } return encodeGlobalID(typename, id);}export function internalDecodeGlobalID<Types extends SchemaTypes>(builder: PothosSchemaTypes.SchemaBuilder<Types>, globalID: string, ctx: object, info: GraphQLResolveInfo, parseIdsForTypes: { typename: string; parseId: (id: string, ctx: object) => unknown;}[] | boolean) { const decoded = builder.options.relayOptions.decodeGlobalID ? builder.options.relayOptions.decodeGlobalID(globalID, ctx) : decodeGlobalID(globalID); if (Array.isArray(parseIdsForTypes)) { const entry = parseIdsForTypes.find(({ typename }) => typename === decoded.typename); if (!entry) { throw new PothosValidationError(`ID: ${globalID} is not of type: ${parseIdsForTypes .map(({ typename }) => typename) .join(", ")}`); } if (entry.parseId) { return { ...decoded, id: entry.parseId(decoded.id, ctx), }; } return decoded; } if (parseIdsForTypes) { const parseID = info.schema.getType(decoded.typename)?.extensions?.pothosParseGlobalID as (id: string, ctx: object) => string; if (parseID) { return { ...decoded, id: parseID(decoded.id, ctx), }; } } return decoded;}
pothos

Version Info

Tagged at
a year ago