Closed gitrojones closed 3 months ago
Latest commit: db3aab8dc26c57ada4b4832a7f75b9848e2ff4b3
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
This seems to already be possible by setting the type before PgCodecsPlugin executes.
const makeSetCodecTypePlugin = (
databaseTypeName: string,
inputGraphqlTypeName: string,
outputGraphqlTypeName: string = inputGraphqlTypeName,
): GraphileConfig.Plugin => ({
name: `SetCodecTypePlugin_${databaseTypeName}_${inputGraphqlTypeName}_${outputGraphqlTypeName}`,
version: "0.0.0",
schema: {
hooks: {
init: {
before: ["PgCodecsPlugin"],
callback(_, build) {
for (const codec of build.allPgCodecs) {
console.log(codec.extensions?.pg?.name, databaseTypeName);
if (codec.extensions?.pg?.name === databaseTypeName) {
build.setGraphQLTypeForPgCodec(
codec,
"input",
inputGraphqlTypeName,
);
build.setGraphQLTypeForPgCodec(
codec,
"output",
outputGraphqlTypeName,
);
}
}
return _;
},
},
},
},
});
However, if you want to alias one scalar type over another it's not currently possible because those scalars don't exist until after PgCodecsPlugin runs
You only reference them by name, so this shouldn't matter. That's one of the major reasons that the new system works the way it does: all of the potential types are registered up front, but none are actually created until later.
If this doesn't address your need, please create a reproduction of your issue. I'm not keen to encourage overwriting of things like codecs or GraphQL types; overwriting things makes debugging hard.
Description
Currently it's possible to alias a custom scalar type with a primitive type (Int, String, etc..) in the init phase with
build.setGraphQLTypeForPgCodec
out of the box with an init hook. However, if you want to alias one scalar type over another it's not currently possible because those scalars don't exist until afterPgCodecsPlugin
runs and once set they cannot be re-set.It seems reasonable that a hook set to run after
PgCodecsPlugin
but within the init phase should be able to re-set any of those automatically generated types.Performance impact
Unknown
Security impact
Unknown
Checklist
yarn lint:fix
passes.yarn test
passes.RELEASE_NOTES.md
file (if one exists).