-
Notifications
You must be signed in to change notification settings - Fork 275
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
Cannot make a custom ID Scalar #936
Comments
What do you mean by |
I meant using a custom method to make the ID graphql type didn't make the custom scalar work. |
Just tried adding this, but it looks to be a limitation upstream in graphql-js: If you want to be able to customize a builtin scalar globally, it looks like you need to patch the methods directly on the instance: import { graphql, GraphQLID } from 'graphql'
import { makeSchema, queryField } from 'nexus'
it('can replace known scalars', async () => {
GraphQLID.parseValue = function parseValue(value) {
// decode string if needed
return value.replace(/$MYID_/, '')
}
GraphQLID.serialize = function serialize(value) {
// encode value
return `MYID_${value}`
}
const schema = makeSchema({
types: [
queryField('id', () => ({
type: 'ID',
resolve() {
return `Test`
},
})),
],
outputs: false
})
expect(
await graphql({
schema,
source: `{ id }`,
})
).toEqual({ data: { id: 'MYID_Test' } })
}) |
I think it is possible to override the scalar in the resolvers of the given server, I know I was able to do that in apollo. Maybe look that way? |
I'm trying to make a custom scalar to replace the ID to allow for a new ID format. I've simplified the implementation for this issue. This Scalar should strip the
MYID_
from the beginning of input IDs and add it to the data of the output IDs. However it does nothing.I tried renaming
asNexusMethod
tomyID
and using that instead. Still does nothing. If I change thename
then I'm able to get the desired behavior. However, I need to allow for the new ID without updating every single client so I can't change the name of ID. Any advice?The text was updated successfully, but these errors were encountered: