GraphQL Apollo Enum in Query

Viewed 281

On the Server, I defined the enum and query in the schema:

type Query {
    hello: String!
    getData(dataType: DataType!): [DataPoint]
} 

enum DataType {
        ACCOUNT,
        USER,
        COMPANY
    }
...

On the Client:

export const GET_DATA = gql`
    query($dataType: DataType) {
        getData(dataType: $dataType) {
          ...
        }
    }
`;

Whenever I try calling the query in the ApolloClient I get a validation error since Apollo expects the value, not as a string, so instead of "ACCOUNT", it expects ACCOUNT. Trying to pass integer values obviously also doesn't do the trick.

  const dataResponse = useQuery(GET_DATA, {
       variables: { dataType: "ACCOUNT" },
  });

What would I need to change about the server or client-side implementation to be able to correctly pass the Enum value as a variable? Ideally, I would like to have the possibility to pass the string value into the useQuery method.

0 Answers
Related