graphile-engine icon indicating copy to clipboard operation
graphile-engine copied to clipboard

Add hook for GraphQLScalarType

Open ab-pm opened this issue 4 years ago • 2 comments

Feature description

There is no hook for GraphQLScalarType. We should add one!

Motivating example

I wanted to hook into the creation of the scalar types in pgTypes plugin. In particular, I wanted to rename Date to IsoDate (ok, there's an inflection for that), update the description (would've been possible by hooking into wrapDescription, but it's not really meant for that), and update the parsing methods to validate a strict YYYY-MM-DD format not everything that Postgres allows.

I got a workaround that overwrites build.graphql.GraphQLScalarType before pgTypesPlugin uses it, but it's really ugly.

Supporting development

ab-pm avatar Sep 16 '21 17:09 ab-pm

Love bullet 1 :raised_hands:

benjie avatar Sep 16 '21 19:09 benjie

Incidentally if you fancied having a pop at this yourself; you basically need code like this:

https://github.com/graphile/graphile-engine/blob/6692c2a65f406c55c3d1edfff51c8f7cc2296956/packages/graphile-build/src/makeNewBuild.js#L796-L806

Search through that file (and the .d.ts that goes with it) for GraphQLEnumType and add similar code for GraphQLScalarType (except even simpler since you don't have to deal with values). Then find where we've done new GraphQLScalarType( in the codebase and replace it with newWithHooks(GraphQLScalarType, and you're basically done I think.

(It's a bit more effort than I make it sound.)

benjie avatar Sep 16 '21 19:09 benjie

V5 does indeed have a GraphQLScalarType hook.

benjie avatar Sep 27 '23 16:09 benjie