I have the following schema definition:
enum CommunityType {
INTEREST
COMPANY
INDUSTRY
}
...
extend type Mutation {
createCommunity(name: String!, type: CommunityType): Community
}
And the following mutation:
mutation CreateCommunity($name: String!, $type: CommunityType) {
createCommunity(name: $name, type: $type) {
id
name
type
}
}
Apollo generated the correct TypeScript types for me as well:
export interface CreateCommunity_createCommunity {
__typename: "Community";
id: string | null;
name: string | null;
type: CommunityType | null;
}
export interface CreateCommunity {
createCommunity: CreateCommunity_createCommunity | null;
}
export interface CreateCommunityVariables {
name: string;
type?: CommunityType | null;
}
And global types:
/**
* CommunityType
*/
export enum CommunityType {
COMPANY = "COMPANY",
INDUSTRY = "INDUSTRY",
INTEREST = "INTEREST",
LOCATION = "LOCATION",
MINISTRY = "MINISTRY",
}
When I use the mutation like so
const [create, {
loading,
error,
}] = useMutation<CreateCommunity, CreateCommunityVariables>(CREATE_COMMUNITY, {
variables: {
name: title,
type: CommunityType.COMPANY,
},
});
I get this error when invoking create
:
GraphQL error: Expected a value of type "CommunityType" but received: "company"
It seems like Apollo Client somehow transforms the enum value COMPANY
to lower case.
I'm using apollo-client 2.6.8
. Edit: I upgraded to apollo-client 3.3.6
, same problem