Looking for a way to fetch data from graphql in my vue project and store it in a variable. The function is asynchronous and the value of rawID needs to be awaited. However, there is a possibility that it could result in undefined, causing an error in the "generateID" function. As a TypeScript developer, I would typically handle this by typing it as something OR undefined, but in JavaScript that approach does not work.
async click() {
const rawID = await generateID()
const ID = rawID.data.theDataINeed
console.log(rawID, ID)
},
generateID() {
const CREATE_ID = gql`
mutation {
theDataINeed
}
`
return this.$axios.post('theGraphQLEndPoint', {
query: print(CREATE_ID),
})
},