Created
July 15, 2025 10:10
-
-
Save jsmnbom/55f8c685089d32bc102d40b1d232520b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { EXPORTABLE } from 'graphile-utils' | |
| export default { | |
| name: 'ULIDPlugin', | |
| description: 'Adds support for ULID type (specifically https://github.com/pksunkara/pgx_ulid).', | |
| version: '0.0.0', | |
| gather: { | |
| hooks: { | |
| pgCodecs_findPgCodec(info, event) { | |
| if (event.pgType.typname === 'ulid') { | |
| event.pgCodec = { | |
| name: 'ULID', | |
| sqlType: info.lib.sql.identifier('ulid'), | |
| fromPg: value => value, | |
| toPg: value => value, | |
| attributes: undefined, | |
| extensions: { oid: event.pgType._id }, | |
| executor: null, | |
| } | |
| } | |
| }, | |
| }, | |
| }, | |
| schema: { | |
| hooks: { | |
| init(_, build) { | |
| const { stringTypeSpec, graphql: { GraphQLError }, input: { pgRegistry: { pgCodecs } } } = build | |
| build.registerScalarType( | |
| 'ULID', | |
| {}, | |
| () => | |
| stringTypeSpec( | |
| build.wrapDescription( | |
| 'A Universally Unique Lexicographically Sortable Identifier ([ULID](https://github.com/ulid/spec)).', | |
| 'type', | |
| ), | |
| EXPORTABLE( | |
| GraphQLError => (string) => { | |
| // ULID spec: 26 Crockford base32 characters (uppercase, no hyphens) | |
| if (!/^[0-9A-HJKMNP-TV-Z]{26}$/i.test(string)) { | |
| throw new GraphQLError( | |
| 'Invalid ULID, expected 26 Crockford base32 characters (no hyphens, case-insensitive)', | |
| ) | |
| } | |
| return string | |
| }, | |
| [GraphQLError], | |
| ), | |
| 'ULID', | |
| ), | |
| 'ULIDPlugin', | |
| ) | |
| build.registerCursorConnection?.({ | |
| typeName: 'ULID', | |
| scope: {}, | |
| nonNullNode: false, | |
| }) | |
| build.setGraphQLTypeForPgCodec(pgCodecs.ULID, 'input', 'ULID') | |
| build.setGraphQLTypeForPgCodec(pgCodecs.ULID, 'output', 'ULID') | |
| return _ | |
| }, | |
| }, | |
| }, | |
| } satisfies GraphileConfig.Plugin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment