Anyone please helppppp!!! I am trying to use TMDB movie api to post a rating, check out the link here for their docs:https://developer.themoviedb.org/reference/movie-add-rating, however i face an issue that it keeps showing me the below error when i implement to Graphql code for Mutation, how do i solve it:
"errors": [
{
"message": "String cannot represent value: { success: false, status_code: 34, status_message: "The resource you requested could not be found." }",
"locations": [
{
"line": 4,
"column": 5
}
],
"path": [
"addMovieRatings",
"message"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"stacktrace": [
"GraphQLError: String cannot represent value: { success: false, status_code: 34, status_message: "The resource you requested could not be found." }",
" at GraphQLScalarType.serialize
here is my 3 code files:
schema.js:
type Rating {
id: ID!
rating: Float!
}
type AddMovieRatingsResponse {
code: Int!
success: Boolean!
message: String!
rating: Rating
}
type Mutation {
addMovieRatings(id: ID!, rating: Float!): AddMovieRatingsResponse!
}
movie-api.js:
class MovieAPI extends RESTDataSource {
baseURL = `https://api.themoviedb.org/3/`;
async addMovieRatings(id, rating) {
const response = await this.patch(
`movie/${id}/rating?api_key=${process.env.API_KEY}`,
{ rating }
);
return response;
}
}
module.exports = MovieAPI;
resolvers.js:
const resolvers = {
Mutation: {
addMovieRatings: async (_, { id, rating }, { dataSources }) => {
try {
const result = await dataSources.movieAPI.addMovieRatings(id, rating);
console.log(result);
return {
code: 200,
success: true,
message: `Successfully added rating for movie with id: ${id}`,
rating: result.rating,
};
} catch (err) {
return {
code: err.extensions.response.status,
success: false,
message: err.extensions.response.body,
rating: null,
};
}
},
},
}