简体   繁体   中英

Angular Apollo: Error: GraphQL error: Unknown argument “username” on field “AuthLogin” of type “Mutation”

I have this error on my angular app, using apollo for graphql

ERROR Error: GraphQL error: Unknown argument "username" on field "AuthLogin" of type "Mutation".

在此处输入图像描述

mutations.ts

import gql from 'graphql-tag';

export const AuthLogin = gql`
  mutation($username: String, $password: String) {
    AuthLogin(username: $username, password: $password) {
      auth
    } 
  }`;

login.component.ts


import {AuthLogin} from '../mutations';

this.apollo.mutate({
        mutation: AuthLogin, variables: { username: this.username, password: this.password }
      }).subscribe( (data) => {
        console.log(data)
      });

backend schema.graphql

input LoginInput {
    username: String!
    password: String!
}

type Mutation {
    AuthLogin(data:LoginInput): AuthResolver
}

Solved! The data: {... type was missing in here:

export const AuthLogin = gql`
  mutation AuthLogin($username: String!, $password: String!) {
    AuthLogin( data: {username: $username, password: $password} ) {
      auth
    } 
  }`;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM