0

Using https://graphql-code-generator.com/, the type in GraphQL is just set to String, but in my client code with the dropdown input, the type is more specific because it is derived from the dropdown options themselves:

export const CODE_NAME_MAP = {
  AFG: 'Afghanistan',
  AGO: 'Angola',
  // ...
export type Country = typeof CODE_NAME_MAP[keyof typeof CODE_NAME_MAP]

In this case, the graphql data returned from the server has a less specific type than what the client does. Is there a better way to represent these types so they're the same? I got validation errors trying to use the country names in an enum.

Garrett
  • 11,451
  • 19
  • 85
  • 126

1 Answers1

1

It's a bit hard to help since you haven't provided what the expected type is, but have you considered declaring an Object Type? Then you can match the type to what you're expecting and assign it correctly within your schema.

Forrest
  • 1,370
  • 9
  • 20