Hey guys! I'm not sure if this is a GraphCool or A...
# prisma-whats-new
k
Hey guys! I'm not sure if this is a GraphCool or Apollo problem (or my own error), but when I try to create a new user using a mutation, it works in the Graphcool console (the user gets created) but it also returns an error of
Error caught: TypeError: Cannot read property 'variables' of undefined
n
@kaihuang724 do you get this error in the Console itself?
k
In my dev console, yeah
n
You mentioned Apollo first, did you try that same mutation from Apollo as well?
k
Sorry, I wasn't clear. I'm actually trying this from my simulator running a React Native project with Apollo.
n
ok, so you don't see that error when running the mutation in the playground, right?
k
No, just in the simulator
n
So somewhere in your code you're trying to access a
variables
property of something that's undefined 🙂 Can you share your code?
k
Copy code
// Props Declaration
type Props = {
  client: ApolloClient,
  createUser: ({
    variables: {
      idToken: string,
      name: ?string,
      email: ?string
    }
  }) => { id: string}
}

class Login extends Component {
  _lock: Auth0Lock
  props: Props

  constructor(props) {
    super(props)
    this._lock = new Auth0Lock({
      clientId: clientId,
      domain: domain,
      useBrowser: true
    })
  }

  _showLogin() {
    this._lock.show({
      closable: true,
      connections: ['Username-Password-Authentication']
    }, async (err, profile, token) => {
      if (!err) {
        AsyncStorage.setItem('token', token.idToken)
          .then(() => {
            this.props.client.resetStore()
          })
        this.props.createUser({
            variables: {
              idToken: token.idToken,
              name: profile.name
              email: profile.email
            }
          })
          .then((data) => {
            console.log("Data received: " + data)
            Actions.registration({ type: ActionConst.REPLACE })
          })
          .catch((err) => {
            console.log("Error caught: " + err)
            AsyncStorage.removeItem('token')
              .then(() => this.props.client.resetStore())
            // Actions.home({ type: ActionConst.REPLACE })
          })
      } else {
        console.log(err)
      }
    })
  }
Absolutely, there's my code for the login procedure. I'm using Auth0 for user auth
n
how are you passing in the
createUser
prop?
k
Copy code
const createUserMutation = gql`
mutation createUser($idToken: String!, $name: String, $email: String) {
  createUser(
    authProvider: {
      auth0: {
        idToken: $idToken
      }
    },
    name: $name,
    email: $email
  ){
    id
  }
}`

export default withApollo(
  graphql(createUserMutation,
    { name: 'createUser' }
  )(Login))
this section for the mutation?
n
are you sure this is the section that is throwing the error?
k
yeah, line 73 is what's throwing the error
n
which line is that? 🙂
k
sorry, this line `.catch((err) => { console.log("Error caught: " + err)
n
so you see the result of
console.log("Data received: " + data)
before?
k
no, that never gets called
but i do get this back
Copy code
action APOLLO_MUTATION_RESULT @ 10:02:58.804
core.js:118  prev state Object {apollo: Object}
core.js:122  action     Object {type: "APOLLO_MUTATION_RESULT", result: Object, mutationId: "3", document: Object, operationName: "createUser"…}document: ObjectextraReducers: Array(0)mutationId: "3"operationName: "createUser"result: Objectdata: ObjectcreateUser: Objectid: "cj338n3c61d5a0192xrbp0py9"__typename: "User"__proto__: Object__proto__: Object__proto__: Objecttype: "APOLLO_MUTATION_RESULT"update: undefinedupdateQueries: Objectvariables: Object__proto__: Objectconstructor: function Object()hasOwnProperty: function hasOwnProperty()isPrototypeOf: function isPrototypeOf()propertyIsEnumerable: function propertyIsEnumerable()toLocaleString: function toLocaleString()toString: function toString()valueOf: function valueOf()__defineGetter__: function __defineGetter__()__defineSetter__: function __defineSetter__()__lookupGetter__: function __lookupGetter__()__lookupSetter__: function __lookupSetter__()get __proto__: function __proto__()set __proto__: function __proto__()
core.js:130  next state Object {apollo: Object}
sorry about the formatting - it's basically the object from Apollo saying that the mutation result succeeded
n
is the user created after all?
k
yep, the user gets created
n
Ok. I can't see the problem right now, but it's something in your app code after the mutation
k
Yeah 🤔 I can't really see the problem
I'll try StackOverflow - thanks for the help though! Just wanted to see if you guys have ever come across this problem
n
Sure, no problem! Feel free to link it here
k
Figured out the problem- although not sure what was causing it lol. SO link here: https://stackoverflow.com/questions/44165375/react-native-graphql-apollo-error-thrown-during-mutation
n
hah, interesting