mattbryanswan
12/14/2017, 8:03 PMreturn api.request<{ createUser: User }>(mutation, variables).then(r => r.createUser.id)
from line 87 of signup.ts in the auth/email-password template?mattbryanswan
12/14/2017, 8:03 PMmatic
12/14/2017, 8:42 PM<>
can be omitted, so it is actually return api.request(mutation, variables).then(r => r.createUser.id)
, which is just a Promise
.matic
12/14/2017, 8:43 PM.then(anotherPromise)
after api.request(mutation. variables).then(r => r.createUser.id)
so you get something like api.request(mutation, variables).then(r => r.createUser.id).then(anotherPermission)
matic
12/14/2017, 8:45 PMtry...catch...
and use await
to make sure first request is fulfilled and then await
your mutation, or just return it.matic
12/14/2017, 8:47 PMasync function createGraphcoolUser(api: GraphQLClient, email: string, password: string): Promise<string> {
const mutation = `
mutation createGraphcoolUser($email: String!, $password: String!) {
createUser(
email: $email,
password: $password
) {
id
}
}
`
const variables = {
email,
password: password,
}
try {
const user = await api.request<{ createUser: User }>(mutation, variables)
.then(r => r.createUser.id)
const res = await api.request(yourMutation, yourVariables)
return res
} catch(err) {
throw err
}
}
mattbryanswan
12/31/2017, 11:07 PMmatic
12/31/2017, 11:24 PM