Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook for GraphQLScalarType #757

Closed
2 tasks done
ab-pm opened this issue Sep 16, 2021 · 3 comments
Closed
2 tasks done

Add hook for GraphQLScalarType #757

ab-pm opened this issue Sep 16, 2021 · 3 comments

Comments

@ab-pm
Copy link
Contributor

ab-pm commented Sep 16, 2021

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

@benjie
Copy link
Member

benjie commented Sep 16, 2021

Love bullet 1 🙌

@benjie
Copy link
Member

benjie commented Sep 16, 2021

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

const commonContext = {
type: "GraphQLEnumType",
scope,
};
newSpec = builder.applyHooks(
this,
"GraphQLEnumType",
newSpec,
commonContext,
`|${newSpec.name}`
);

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
Copy link
Member

benjie commented Sep 27, 2023

V5 does indeed have a GraphQLScalarType hook.

@benjie benjie closed this as completed Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants