I am using TypeScript and have a GraphQL query definition called using Apollo's useQuery. Documentation says the call should be typed, but I receive an ESLint error for data
being an any
value. How can I fix this?
export const listProducerOrgStewards = gql`
query listProducerOrgStewards($user: String) {
listProducerOrgStewards(user: $user) {
...
}
`;
const { loading, data, error } = useQuery(listProducerOrgStewards, {
fetchPolicy: 'cache-and-network',
});
You have a few options:
useQuery
. This would look something like the following:import { ListProducerOrgStewardsQuery, ListProducerOrgStewardsQueryVariables
} from 'src/gql/types.ts`
const { loading, data, error } = useQuery<ListProducerOrgStewardsQuery, ListProducerOrgStewardsQueryVariables>(listProducerOrgStewards, {
fetchPolicy: 'cache-and-network',
});
data
variable typed. This would require some codegen config changes.