TypeScript definitions for the Magento 2 Graphql API
js
import { CmsPage } from 'magento2-graphql-types'
const getData = async () => {
const res = await fetch('https://venia.magento.com/graphql?query=query+getCmsPage%28%24id%3AInt%21%29%7BcmsPage%28id%3A%24id%29%7Burl_key+content+content_heading+title+page_layout+meta_title+meta_keywords+meta_description+__typename%7D%7D&operationName=getCmsPage&variables=%7B%22id%22%3A7%7D')
const resJson = await res.json()
const data = resJson.data.cmsPage as CmsPage
if(data.__typename === "Test"){
//ts2367: This condition will always return 'false' since the types '"CmsPage" | undefined' and '"Test"' have no overlap.
console.log("This never runs!")
}
}
getData()
``