Hello, I want to know how to pass react state into variables apollo.
This is the mutation:
import { gql } from ‘@apollo/client’
import USER_INFO_FRAGMENT from ‘…/…/fragments/users/usercred’
export const REGISTER_RETAILER_MUTATION = gqlmutation createSeller($createroot: CreateRetailerRootInput){ createSeller(createroot: $createroot){ token retailer { ...UserInfoFragment } } } ${USER_INFO_FRAGMENT}
;
const [auth, setAuth] = useState({
username: ‘’,
email: ‘’,
password: ‘’,
passwordConfirmation: ‘’,
name: ‘’,
phone: ‘’
})
const [createSeller,
{ loading: mutationLoading, data, error: mutationError },
] = useMutation(
REGISTER_RETAILER_MUTATION,
{
variables: {
createroot: {
retailer: {
username: auth.username,
email: auth.email,
password: auth.password,
name: auth.name,
phone: auth.phone
}
}
},
onCompleted: ({ createSeller }) => {
setToken(createSeller.token);
history.push('/dashboard')
}
}
);
I am passing, the state but when I execute the submit bottom, shows me this.
[GraphQL error]: Message: NOT_A_NUMBER, Location: [object Object], Path: createSeller
But when I changed to this:
const [createSeller,
{ loading: mutationLoading, data, error: mutationError },
] = useMutation(
REGISTER_RETAILER_MUTATION,
{
variables: {
createroot: {
retailer: {
username: "Nombre",
email: "email@email.com",
password: "password",
name: "name",
phone: "1234561111"
}
}
},
onCompleted: ({ createSeller }) => {
setToken(createSeller.token);
history.push('/dashboard')
}
}
);
it redirects me and save it to the DB, and save the token
I don´t know how to solve this until now. Does anybody knows how to fix this or pass the state
correctly to react.
Kind reacts