I am learning to build a GraphQL API, and I’d like to usethe type enum
In my database, the data looks like this :
const missions = [
{
id: "1",
name: "Mission 1",
status: "in progress",
},
];
And and my schema and resolvers like this :
const typeDefs = gql`
enum Status {
NOTSTARTED
INPROGRESS
COMPLETED
}
type Mission {
id: ID!
name: String!
status: Status!
}
type Query {
missions: [Mission]
mission(id: ID!): Mission
}
const resolvers = {
Query: {
missions() {
return missions;
},
mission(_, args) {
return missions.find((mission) => {
return mission.id === args.id;
});
},
},
};
`;
In Apollo explorer, when I execute the query
query($missionId: ID!){
mission(id: $missionId) {
id
name
status
}
}
I get the error ""Enum "Status" cannot represent value: "in progress"".
If I change the field in my database to status:"INPROGRESS"
, i can execute the query, but I don’t think that is the solution.
I am reading Apollo Server documentation about Enums, and I cannot see clear a way to assign a value to every value from the enum list, so that value matches the value from my database.