const myMutation = gql mutation loginUser($email: String!, $password: String!) { loginUser(email: $email, password: $password) { token } }
;
import { Component } from '@angular/core'; import { Apollo } from 'apollo-angular'; import gql from 'graphql-tag';
@Component({ selector: 'my-component', templateUrl: './my.component.html' }) export class MyComponent { constructor(private apollo: Apollo) {}
login() {
this.apollo
.mutate({
mutation: gql mutation loginUser($email: String!, $password: String!) { loginUser(email: $email, password: $password) { token } }
,
variables: {
email: 'user@example.com',
password: 'secret'
}
})
.subscribe(result => {
// handle result
});
}
}
如果以上步骤未解决问题,请查看控制台或服务器日志以查找任何错误消息。 通常情况下,Mutation操作不起作用的原因是具有无效输入参数或GraphQL服务器上的错误操作名称。