Last active
August 22, 2022 21:59
-
-
Save Juanpablobar/c76d93251878ecd06560d83f91491ab4 to your computer and use it in GitHub Desktop.
VTEX: graphQL query with JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const resolveURLGraphql = () => { | |
let graphql = '' | |
const isProduction = vtex?.renderRuntime?.production | |
let vtexapi = `https://${vtex.renderRuntime.query.origin}` | |
if (isProduction) { | |
graphql = `${vtexapi}/_v/segment/graphql/v1` | |
} else { | |
graphql = `${vtexapi}/_v/private/graphql/v1` | |
} | |
return graphql | |
} | |
const getAppGraphql = () => { | |
const graphqlURL = resolveURLGraphql() | |
const settings = { | |
url: graphqlURL, | |
type: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
data: JSON.stringify({ | |
query: | |
`query (){ | |
@context(provider: ""){} | |
}`, | |
variables: {}, | |
}), | |
} | |
return $.ajax(settings) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment