本文整理汇总了TypeScript中angular2-apollo.Angular2Apollo.mutate方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Angular2Apollo.mutate方法的具体用法?TypeScript Angular2Apollo.mutate怎么用?TypeScript Angular2Apollo.mutate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2-apollo.Angular2Apollo
的用法示例。
在下文中一共展示了Angular2Apollo.mutate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: updateProfile
updateProfile(firstName: string, lastName: string): Observable<ApolloQueryResult> {
return this.apollo
.mutate({
mutation: gql`
mutation updateProfile(
$firstName: String!
$lastName: String!
) {
updateProfile(
firstName: $firstName
lastName: $lastName
) {
firstName
lastName
}
}
`,
variables: {
firstName,
lastName
},
})
.map(({ data }: ApolloQueryResult) => data.updateProfile)
.catch(err => Observable.throw(err));
}
示例2: login
/**
* @param user Credentials for the user to login.
* @returns A promise wrapping the result from the loginUser mutation.
*/
login(user: IScapholdUserInput): Promise<GraphQLResult> {
return this.client.mutate({
mutation: gql`
mutation LoginUser($input: _LoginUserInput!) {
loginUser(input: $input) {
id
token
}
}
`,
variables: {
input: {
username: user.username,
password: user.password
}
}
}).then((result: GraphQLResult) => {
const {data, errors} = result;
if (errors) {
throw errors;
}
this.setCredential(data['loginUser']);
this.syncUser(data['loginUser']['id']);
return result;
});
}
示例3: register
/**
* @param user Credentials for the new user.
* @returns A promise wrapping the result from the createUser mutation.
*/
register(user: IScapholdUserInput): Promise<GraphQLResult> {
return this.client.mutate({
mutation: gql`
mutation CreateUser($input: _CreateUserInput!) {
createUser(input: $input) {
changedUser {
id
username
createdAt
modifiedAt
lastLogin
}
}
}
`,
variables: {
input: {
username: user.username,
password: user.password
}
}
}).then((result: GraphQLResult) => {
const {data, errors} = result;
if (errors) {
throw errors;
}
this.setUser(data['createUser']['changedUser']);
return result;
});
}
示例4: newUser
/**
* Create new user with type player.
* @param user The user.
*/
public newUser(user: User): Observable<User> {
const token = this.login.getToken();
if (!token) {
return Observable.throw("No authentication token");
}
if (!this.connectivityService.isOnline()) {
this.storeForLaterPush(user);
return Observable.from([user]);
}
return this.apollo
.mutate({
mutation: gql`
mutation newUser($token: String!, $user: AutoUser!) {
viewer(token: $token) {
createAutoUser(user: $user) {
_id
}
}
}
`,
variables: {
token,
user,
},
}).map(result => {
return result.data.viewer.createAutoUser as User;
});
}
示例5: submitForm
public submitForm(): void {
if (!this.repoFullName) {
return;
}
this.error = null;
this.apollo.mutate({
mutation: submitRepositoryMutation,
variables: {
repoFullName: this.repoFullName,
},
}).then(() => {
this.router.navigate(['/feed/new']);
}).catch((error) => {
this.error = error.message;
});
}
示例6: executeMutation
executeMutation(argValues) {
this.apolloClient.mutate(this.graphQLBuilder().buildMutation(argValues)).then(({data}) => {
this.mutationResults = data[this.graphQLBuilder().queryName()];
});
}