Skip to content

feat: inline pg-type-mappings plugin into graphile-settings#688

Merged
pyramation merged 5 commits intodevelop-v5from
feat/pg-type-mappings
Feb 5, 2026
Merged

feat: inline pg-type-mappings plugin into graphile-settings#688
pyramation merged 5 commits intodevelop-v5from
feat/pg-type-mappings

Conversation

@pyramation
Copy link
Contributor

@pyramation pyramation commented Feb 5, 2026

Summary

Inlines the graphile-pg-type-mappings plugin from the main branch into graphile-settings as a PostGraphile v5 preset. This plugin maps custom PostgreSQL types to GraphQL scalar types.

Default mappings:

  • email, hostname, url, origin → String

The v4 plugin used builder.hook() patterns. This v5 conversion uses:

  • gather.hooks.pgCodecs_findPgCodec to create codecs for custom types
  • schema.hooks.init to map codecs to GraphQL types

Updates since last revision

  • Removed single_select and multiple_select types - These JSONB domain types have been removed from the type mappings as they are no longer needed
  • Renamed smart comments - All domain type comments changed from @name pgpmInternalType* to @name constructiveInternalType*
  • Simplified domain type validation - Removed heavy regex validation from all domains:
    • email: now just citext (no regex - real validation is email confirmation)
    • hostname: now just text (no regex - real validation is DNS resolution)
    • url, origin, attachment: now just text (no regex)
    • image: jsonb requiring only url key (removed mime requirement and URL regex)
    • upload: jsonb requiring at least one of url, id, or key (removed mime requirement and URL regex)
  • Updated fixtures - The __fixtures__/sqitch/simple-w-exts/extensions/@pgpm/types/ directory updated to match

Companion PR: constructive-db#469 contains the corresponding database-side changes.

Review & Testing Checklist for Human

  • Coordinate merge timing - This PR and constructive-db#469 must be merged together to avoid mismatched type definitions
  • Verify no production usage of single_select/multiple_select - These domain types are being removed; ensure no existing databases depend on them
  • Review simplified validation impact - The removal of regex validation means previously rejected values will now be accepted. Verify this is intentional and application-layer validation exists where needed
  • Test upload domain change - The upload domain now accepts id or key as alternatives to url. Verify this aligns with how uploads are used in the application
  • Test with actual PostgreSQL types - Create a table with an email domain type and confirm it appears as String in the GraphQL schema

Recommended test plan:

  1. Create a test database with the simplified domain types
  2. Insert values that would have failed the old regex validation (e.g., unusual but valid emails)
  3. Verify the GraphQL schema correctly maps these types to String
  4. Test upload domain with {"id": "123"} and {"key": "abc"} objects

Notes

The original v4 plugin source was retrieved from origin/main:graphile/graphile-pg-type-mappings/src/index.ts. The standalone package directory on develop-v5 only contained dist/ and node_modules/ (no source).

Link to Devin run: https://app.devin.ai/sessions/ba45b64c92bb4307bf9e920123213d9e
Requested by: Dan Lynch (@pyramation)


Open with Devin

- Add PgTypeMappingsPlugin that maps custom PostgreSQL types to GraphQL scalars
- Default mappings: email, hostname, url, origin -> String; multiple_select, single_select -> JSON
- Uses v5 gather hooks to create codecs for custom types
- Uses v5 schema hooks to map codecs to GraphQL types
- Add PgTypeMappingsPreset to ConstructivePreset
- Export plugin and types from plugins/index.ts
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- Remove single_select and multiple_select type mappings (jsonb types)
- Simplify TypeMapping interface to only support String type
- Remove JSON-related code from fromPg function
- Keep only email, hostname, origin, url mappings
… rename to constructiveInternalType*

- Remove single_select and multiple_select domain files from fixtures
- Rename pgpmInternalType* to constructiveInternalType* in all domain comments
- Update pgpm.plan to remove single_select/multiple_select entries
- email: remove complex regex, keep as citext
- hostname: remove regex
- url: remove regex
- origin: remove regex
- attachment: remove regex
- image: jsonb requiring only 'url' key
- upload: jsonb requiring at least one of 'url', 'id', or 'key'
URL validation: ^https?://[^\s]+$
- Must start with http:// or https://
- Must have at least one character after protocol
- No whitespace allowed
@pyramation pyramation merged commit 27d780f into develop-v5 Feb 5, 2026
13 checks passed
@pyramation pyramation deleted the feat/pg-type-mappings branch February 5, 2026 07:43
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant