My current method for making the desired post request looks like this:
async function fetchMediaList(): Promise<MediaListCollection> {
let result = {} as MediaListCollection;
await axios
.post<MediaListCollection>(
"https://graphql.anilist.co/",
{
query: USER_LIST_CURRENT,
variables: {
userId: 831347,
status: MediaListStatus.Current,
type: MediaType.Anime,
},
},
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
}
)
.then((response) => (result = response.data))
.catch((err) => {
throw {
error: err,
};
});
return result;
}
fetchMediaList()
.then((data) => console.log(JSON.stringify(data)))
.catch((err) => console.log(JSON.stringify(err)));
However, the output I receive is:
{"data":{"MediaListCollection":{"lists":[{"name":"Watching","entries":[{"id":158643971,"mediaId":5081,"status":"CURRENT","score":0,"progress":10,"repeat":0,"media":{"title":{"userPreferred":"Bakemonogatari"},"coverImage":{"extraLarge":"https://s4.anilist.co/file/anilistcdn/media/anime/cover/large/bx5081-YpAE43HLQKqz.png"},"format":"TV","status":"FINISHED","episodes":15,"averageScore":83,"isAdult":false,"genres":["Comedy","Drama","Mystery","Psychological","Romance"...
Subsequently, when I attempt to access list entry 0:
fetchMediaList()
.then((data) => console.log(JSON.stringify(data.lists![0])))
.catch((err) => console.log(JSON.stringify(err)));
I receive an empty object:
{}
It appears that the response contains a larger object called "data," is it possible to overcome this without manually specifying each type?