Skip to content

Instantly share code, notes, and snippets.

@thawkin3
Created January 30, 2021 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thawkin3/e47dbaae2c44bd8d2bd597d1b53cde7c to your computer and use it in GitHub Desktop.
Save thawkin3/e47dbaae2c44bd8d2bd597d1b53cde7c to your computer and use it in GitHub Desktop.
Snippet for fetching jokes from the GraphQL API endpoint
fetch('/graphql', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `
query GetAllJokesWithRatings {
jokes {
id
content
ratings {
score
id
jokeId
}
}
}
`,
}),
})
.then(res => res.json())
.then(res => {
jokes.push(...res.data.jokes)
displayNextJoke()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment