2017-09-30 6 views
0

Angular Front Endを使用して、入力データがオブジェクトであるGraphqlサーバーでクライアントを作成しています。apolloのオブジェクト変数を渡す角度が無効です

core.es5.js:1020 ERROR Error: Uncaught (in promise): Error: GraphQL error: Variable "$client" got invalid value {"firstname":"ewrer","lastname":"ertrt","organization":"rtrt","email":"ytytyy"}. 
In field "firstname": Unknown field. 
In field "lastname": Unknown field. 
In field "firstName": Expected "String!", found null. 
In field "lastName": Expected "String!", found null. 
Error: GraphQL error: Variable "$client" got invalid value 

私は、変数のエントリ「クライアント」を提示していますどのように関連すると思われる:

const createClient = gql` 
mutation createClient($client: ClientInput!){ 
    createClient(client: $client){ 
    lastName 
    organization 
    } 
} 
`; 
@Component({ 
    selector: 'app-new-client', 
    templateUrl: './new-client.component.html', 
    styleUrls: ['./new-client.component.scss'] 
}) 

export class NewClientComponent implements OnInit { 
    subClient = new Client ('', '', '', ''); 
    submitted = false; 
    loading = true; 
    data: any; 

public modalRef: BsModalRef; 

constructor(private modalService: BsModalService, 
    private router: Router, 
    private apollo: Apollo) {} 

public openModal(template: TemplateRef<any>) { 
     this.modalRef = this.modalService.show(template); 
     } 


    ngOnInit() { 
    } 

    onCreateSubmit() { 

    const newClient = { 
      firstname   : this.subClient.firstName, 
      lastname   : this.subClient.lastName, 
      organization  : this.subClient.organization, 
      email    : this.subClient.email 
      }; 
    this.apollo.mutate({ 
     mutation: createClient, 
     variables: { 
      client : newClient 
     } 
     }).subscribe(data => { 
      console.log('new client created: ' + data); 
      }); 
    } 
} 

問題は、私はこのエラーを取得している:これは、以下の私のコードスニペットです。私は

{ 
    'client': { 
    'firstName': 'Paul', 
    'lastName': 'Smith', 
    'organization': 'Truckers Association', 
    'email': '[email protected]' 
    } 
} 

{ 
       client : newClient 
      } 

を交換した場合それが正常に動作します。私がどこに間違っているのか誰にでも教えてくれますか?

答えて

1

エラーメッセージに示すように、newClient変数に割り当てられたオブジェクトには、2つの必須プロパティ - firstNameおよびlastNameがありません。意図せずそれらのプロパティーの名前を間違って変更しましたfirstnamelastname(すべて小文字)。

関連する問題