In my vue project, i want to fetch something from graphql and store it to a variable. function is async and the value of rawID must be awaited for. Since this could obviously also result in undefined, the "generateID" complains that it is undefined. Im a TS native dev and in TS i would just tye this as something OR undefined but in js that doesnt 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),
})
},
CodePudding user response:
Try with since you're probably using Options API and have generateID
defined in methods
await this.generateID()