Skip to content

Instantly share code, notes, and snippets.

@garethpbk
Created November 20, 2018 17:38
Show Gist options
  • Save garethpbk/d15e6747acb263142a2fa4a89b027510 to your computer and use it in GitHub Desktop.
Save garethpbk/d15e6747acb263142a2fa4a89b027510 to your computer and use it in GitHub Desktop.
apollo-link-state createNewUser function
createNewUser = async (e, action) => {
e.preventDefault();
const currentUsers = client.readQuery({ query: GET_ALL_USERS_QUERY });
const id = currentUsers.users.length + 1;
await action({
variables: {
input: {
id,
...this.state,
},
},
});
this.setState({
name: '',
username: '',
email: '',
address: {
street: '',
suite: '',
city: '',
zipcode: '',
geo: {
lat: '',
lng: '',
},
},
phone: '',
website: '',
company: {
name: '',
catchPhrase: '',
bs: '',
},
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment