在apollo garphql angular中传递对象变量会给出无效值
我正在使用Angular前端在graphql服务器中创建一个客户端,其中输入数据是一个对象。下面是我的代码片段:在apollo garphql angular中传递对象变量会给出无效值,angular,graphql,apollo,Angular,Graphql,Apollo,我正在使用Angular前端在graphql服务器中创建一个客户端,其中输入数据是一个对象。下面是我的代码片段: const createClient = gql` mutation createClient($client: ClientInput!){ createClient(client: $client){ lastName organization } } `; @Component({ selector: 'app-new-client', te
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”有关。如果我替换
{
client : newClient
}
与
它很好用。有人能告诉我哪里出错了吗?正如错误消息所示,分配给
newClient
变量的对象缺少两个必需的属性--firstName
和lastName
。您无意中错误命名了这些属性firstname
和lastname
(全部小写)。正如错误消息所示,分配给newClient
变量的对象缺少两个必需的属性--firstname
和lastname
。您无意中错误命名了这些属性firstname
和lastname
(全部小写)
{
client : newClient
}
{
'client': {
'firstName': 'Paul',
'lastName': 'Smith',
'organization': 'Truckers Association',
'email': 'abc123@truckers.com'
}
}