GraphQL server with CORS.
$ yarn
$ up
With curl:
$ curl -d '{ "query": "{ pet(id: 0) { name }}" }' `up url`?pretty
With fetch()
in the browser:
const body = JSON.stringify({
query: `query {
pet(id: 2) {
name
}
}`
})
const res = await fetch('http://localhost:3000', {
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
method: 'POST',
body
})
console.log(res)
console.log(await res.json())
See the CORS second of the documentation for details.