Created
January 30, 2021 06:08
-
-
Save thawkin3/e47dbaae2c44bd8d2bd597d1b53cde7c to your computer and use it in GitHub Desktop.
Snippet for fetching jokes from the GraphQL API endpoint
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
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