2

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),
            })
        },

1 Answer 1

1

Try with since you're probably using Options API and have generateID defined in methods

await this.generateID()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.