Created
August 8, 2018 14:36
-
-
Save tony-nyagah/9fb3cd00c735f22f9beed7f2a37561af to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Here we define our query as a multi-line string | |
| var query = ` | |
| query ($username: String, $type: MediaType) { | |
| MediaListCollection(userName: $username, type: $type) { | |
| lists { | |
| entries { | |
| status | |
| score(format: POINT_10) | |
| progress | |
| progressVolumes | |
| repeat | |
| priority | |
| notes | |
| startedAt { year, month, day } | |
| completedAt { year, month, day } | |
| media { | |
| idMal | |
| title { romaji } | |
| episodes | |
| chapters | |
| volumes | |
| siteUrl | |
| } | |
| } | |
| } | |
| } | |
| } | |
| `; | |
| // Define our query variables and values that will be used in the query request | |
| var variables = { | |
| username: username_as_string, | |
| type: the_word_ANIME_or_Manga_as_string | |
| }; | |
| // Define the config we'll need for our Api request | |
| var url = 'https://graphql.anilist.co', | |
| options = { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Accept': 'application/json', | |
| }, | |
| body: JSON.stringify({ | |
| query: query, | |
| variables: variables | |
| }) | |
| }; | |
| // Make the HTTP Api request | |
| fetch(url, options).then(handleResponse) | |
| .then(handleData) | |
| .catch(handleError); | |
| function handleResponse(response) { | |
| return response.json().then(function(json) { | |
| return response.ok ? json : Promise.reject(json); | |
| }); | |
| } | |
| function handleData(data) { | |
| console.log(data); | |
| } | |
| function handleError(error) { | |
| alert('Error, check console'); | |
| console.error(error); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment