ID typescript type #105
-
It appears as though ID: {
Input: string;
Output: string;
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I generally re-define it as string like you mentioned, but the default is the way it is because the graphql server implementations (and graphql js itself) allow numbers to be passed through for ids. I like ids always being strings, but its not something that is enforced by default, so if you want it to be type-safe you need to find a way convert your inputs. I've done this a couple different ways, but I don't have a method I feel comfortable recommending. It can be done with a custom girapqhl plugin that wraps resolvers (the way globalId input parsing works in the relay plugin is the closest example I can think of). It can be handled by a custom plugin for your server (apollo and graphql helix both have ways to add custom validation logic), or I believe you can overwrite a method on the ID scalar so that it either throws or coerces numbers to strings. Each of these methods have downsides.
Sorry I don't have a simple answer, but I hope that helps. |
Beta Was this translation helpful? Give feedback.
I generally re-define it as string like you mentioned, but the default is the way it is because the graphql server implementations (and graphql js itself) allow numbers to be passed through for ids. I like ids always being strings, but its not something that is enforced by default, so if you want it to be type-safe you need to find a way convert your inputs. I've done this a couple different ways, but I don't have a method I feel comfortable recommending. It can be done with a custom girapqhl plugin that wraps resolvers (the way globalId input parsing works in the relay plugin is the closest example I can think of). It can be handled by a custom plugin for your server (apollo and graphql …