Make a mutation call in angular (getting “Http failure response for https://localhost:8080/graphql: 400 Bad Request”)

Make a mutation call in angular (getting “Http failure response for https://localhost:8080/graphql: 400 Bad Request”)


0

Im new to both GraphQL and angular im trying to follow the documentation but not able to make a mutation.
Below is the ts file code


export const USER_SIGNUP = gql`
  mutation AddUser($userInput: UserInput) {
    addUser(userInput: $userInput) {
      id
      name
      email
      password
    }
  }
`;

import { Component } from '@angular/core';
import { Apollo } from 'apollo-angular';
import { USER_SIGNUP } from 'src/app/graphql/user';

@Component({
  selector: 'app-sign-up',
  templateUrl: './sign-up.component.html',
  styleUrls: ['./sign-up.component.scss'],
})
export class SignUpComponent {

  constructor(private apollo: Apollo) {}

  userSignUp() {
    this.apollo
      .mutate({
        mutation: USER_SIGNUP,
        variables: {
          userInput: {
            name: 'YRT',
            email: 'RTRT',
            password: '1542',
          },
        },
      })
      .subscribe(
        (data) => {
          console.log(data);
        },
        (err) => {
          console.log(err.message);
        }
      );
  }
}

And below is the html file code

<div class="sign-up-main-container">
  <div>
    <app-auth-bg-component></app-auth-bg-component>
  </div>
  <form (ngSubmit)="userSignUp()" class="sign-up-form">
    <div>
      <label>Name</label>
      <div class="sign-up-input-cont">
        <input type="text" placeholder="Enter your name." />
      </div>
    </div>
    <div>
      <label>Email</label>
      <div class="sign-up-input-cont">
        <input type="text" placeholder="Enter your email." />
      </div>
    </div>
    <div>
      <label>Password</label>
      <div class="sign-up-input-cont">
        <input [type]="passwordType" placeholder="Enter your password." />
      </div>
    </div>
    </div>
    <button type="submit">Signup</button>
  </form>
</div>

The below is my nestjs code for user resolver where i have defined the mutation

import { Resolver, Query, Mutation, Args } from '@nestjs/graphql';
import { UserService } from './user.service';
import { User, UserInput } from './users.model';

@Resolver()
export class UserResolver {
  constructor(public userService: UserService) {}

  @Query(() => String)
  hello() {
    return 'hello';
  }

  @Mutation(() => User)
  addUser(@Args('userInput') userInput: UserInput) {
    return this.userService.addUser(userInput);
  }
}

I have followed the documentation but dont know why im getting this error ("Http failure response for https://localhost:8080/graphql: 400 Bad Request") please help me with this.


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

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