Skip to content

Instantly share code, notes, and snippets.

@Juanpablobar
Last active August 22, 2022 21:59
Show Gist options
  • Save Juanpablobar/c76d93251878ecd06560d83f91491ab4 to your computer and use it in GitHub Desktop.
Save Juanpablobar/c76d93251878ecd06560d83f91491ab4 to your computer and use it in GitHub Desktop.
VTEX: graphQL query with JS
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