Error react type mutation

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

@Cesar_Adan are you using a phone number parsing library of some kind on your server? My guess is that your app is sending an empty string in for the phone number, and your parsing library is throwing the NOT_A_NUMBER error. I would recommend console.log-ing / debugging your auth state right before you execute your mutation (so right before you call the createSeller execution function), to make sure the state is properly set. The error you’re seeing leads me to believe your default initial state is being passed to the server.

Hello hwillson

thanks for your answer. Yes, I am using libphonenumber-js

const { parsePhoneNumber } = require(“libphonenumber-js”);
Yes, I check the console.log and the state is writing correctly, just the error but after I change the value String to Int in the type definition, graphql-tools/merge crash and showed me this error.

node_modules/@graphql-tools/merge/index.cjs.js:785
for (const type of types) {
^

TypeError: types is not iterable

I make a simple replication of the config I am using for.

It does not make anything, just a quick view of the way the project is build

Does somebody know what is the problem? and how to solve it?

This is the problem and the open with the code I am using.

Kind regards

@hwillson

Here is the capture of what happend when I add the console.log and also the result is an object, whn I click submit it returns it.

All the data is passing as a string

Hi @Cesar_Adan - I don’t quite follow your updates here. From your console.log’s I don’t see any phone numbers being dumped. The NOT_A_NUMBER error is coming from libphonenumber-js trying to parse something that isn’t a number, so you should look into debugging the data your resolvers are receiving on the server side, before you call parsePhoneNumber. Whatever data you’re running through that function is the problem; it can’t be parsed.

Hello, thanks for the help @hwillson. I solved it by just changing the loadFileSync to export resolver by resolver and schema by schema and also use the gql of apolo-servr-express and ait into and array to merges them.

That solves the problem the mutations was ok in React. All I need to do was to change the apollo-server merge schema and types. Also if you know what is the best way to do this for productions and the apollo team way.

I would thank you very much