vuegraphql
07/08/2018, 1:12 AMKyleG
07/08/2018, 1:41 AMvuegraphql
07/08/2018, 2:02 AMvuegraphql
07/08/2018, 2:02 AMKyleG
07/08/2018, 2:07 AMexport const CREATE_USER_MUTATION = gql`
mutation createUser($email: String!, $password: String!, $first_name: String!, $last_name: String!, $phone_number: String!) {
createUser(
user: {
email : $email,
password : $password,
first_name : $first_name,
last_name : $last_name,
phone_number : $phone_number
}
) {
metaData {
message,
type
}
}
}
`;
The variables (like $email
) are being swapped out AFAIK, so if you simply define the user object in the mutation and fill it out like I do above that would likely work.KyleG
07/08/2018, 2:09 AMKyleG
07/08/2018, 2:14 AM# In schema.graphql
input CreateUserInput {
email: String!
password: String!
first_name: String!
last_name: String!
phone_number: String!
}
# In your client
export const CREATE_USER_MUTATION = gql`
mutation createUser($create_user_input: CreateUserInput!) {
createUser(
user: $create_user_input
) {
metaData {
message,
type
}
}
}
`;
If you're using Apollo, I'll have to point towards another example bit of code:
https://github.com/TiE23/metric-teacher/blob/6605869ff7104fa3982cb71b81d39a89766e16a7/client/src/components/Login.js#L100
While my code is like so:
const result = await this.props.signupMutation({
variables: {
fname: this.state.fname,
lname: this.state.lname,
email: utils.customNormalizeEmail(this.state.email),
password: this.state.password,
},
Yours might look like this:
const result = await this.props.createUserMutation({
variables: {
user: {
email: utils.customNormalizeEmail(this.state.email),
password: this.state.password,
first_name: this.state.first_name,
last_name: this.state.last_name,
phone_number: this.state.phone_number,
},
},
I don't know if this'll work for a fact. Actually, I'm actively writing my project right now and realized that I'll have this same exact situation as you before long with a complicated mutation input object I have. So simply this is what I would try the first time.vuegraphql
07/08/2018, 3:01 AMvuegraphql
07/08/2018, 3:01 AMvuegraphql
07/08/2018, 3:06 AMvuegraphql
07/08/2018, 3:11 AM# In your client
export const CREATE_USER_MUTATION = gql`
mutation createUser($create_user_input: CreateUserInput!) {
createUser(
user: $create_user_input
) {
metaData {
message,
type
}
}
}
`;
vuegraphql
07/08/2018, 3:16 AMvuegraphql
07/08/2018, 3:18 AMvuegraphql
07/08/2018, 3:47 AMvuegraphql
07/08/2018, 3:48 AMKyleG
07/08/2018, 4:09 AMnilan
07/14/2018, 11:14 AM