GraphQL Mutation Query Not working in Apollo Server

GraphQL Mutation Query Not working in Apollo Server


0

helpppp, I am making a movie website using Tmdb api built with Nestjs and Graphql as the backend, I wanted to make a patch request that users can upload their ratings for each of the movies, here is the link to the docs for more details: https://developer.themoviedb.org/reference/movie-add-rating, I am using schema first approach with Nestjs, however i face an error it returns a 404 not found error in my graphql server, below is the details:

"data": {},
  "errors": [
    {
      "message": "404: Not Found",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "addMovieRatings"
      ],
      "extensions": {
        "response": {
          "url": "https://api.themoviedb.org/3/movie/370172/rating/8/?api_key=_______",
          "status": 404,
          "statusText": "Not Found",
          "body": {
            "success": false,
            "status_code": 34,
            "status_message": "The resource you requested could not be found."
          }
        }

Currently there is no docs that teach me how to use PatchRequest along with Nestjs service so Im struggling with it, here is
ratings.service.ts:

import { Injectable } from '@nestjs/common';
import { RESTDataSource, PatchRequest } from '@apollo/datasource-rest';

interface PostRatingsRequest extends PatchRequest {
  value: number;
}

@Injectable()
export class RatingsService extends RESTDataSource {
  constructor() {
    super();
  }
  baseURL = `https://api.themoviedb.org/3/`;

  async addMovieRating(id: string, rating: number) {
    const requestBody: PostRatingsRequest = {
      value: rating,
    };
    const response = await this.patch(
      `${this.baseURL}/movie/${id}/rating?api_key=${process.env.API_KEY}`,
      requestBody,
    );
    return response;
  }
}

ratings.resolver.ts:

import { Args, Mutation, Resolver } from '@nestjs/graphql';
import { RatingsService } from './ratings.service';

@Resolver()
export class RatingsResolver {
  constructor(private ratingsService: RatingsService) {}

  @Mutation()
  async addMovieRatings(
    @Args('id') id: string,
    @Args('rating') rating: number,
  ) {
    return this.ratingsService.addMovieRating(id, rating);
  }
}

schema.graphql:

type Rating {
  id: ID!
  rating: Float!
}

type AddMovieRatings {
  code: Int!
  success: Boolean!
  message: String!
  rating: Rating
}

type Mutation {
  addMovieRatings(id: ID!, rating: Float!): AddMovieRatings!
}


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *