Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

js solution for async query is potentially undefined

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

await this.generateID()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading