Hi, I am testing this from the local state with apollo client and it gives me this error when invoking the mutate method.
ApolloError.js: 43 Uncaught (in promise) Error: Network error: Can not read property 'Mutation' of undefined
---------- Code:
-------- updatePagPrincipal.js
import gql from 'graphql-tag';
export default gql'
mutation updatePagPrinc($index: String! , $value: String!) {
updatePagPrinc(index: $index, value: $value) @client {
bienvenido
descripcion
}
}
'
------ FormLogin.js
import React, {Fragment}from 'react'
import { compose, graphql } from 'react-apollo';
import updatePagPrincipal from '../../LocalState/graphql/updatePagPrincipal'
class FormLogin extends React.Component{
constructor(props) {
super(props);
// create a ref to store the textInput DOM element
this.titleInput = React.createRef();
this.descriptionInput = React.createRef();
}
render(){
const { updatePagPrinc } = this.props
return (
<Fragment>
<form onSubmit={e => {
e.preventDefault();
updatePagPrinc({
variables: {
index: 'Titulo',
value: this.titleInput.current.value
}
})
console.log(this.titleInput.current.value)
this.titleInput.current.value = ""
}}>
<label> Titulo:</label><input type="Text" ref=
{this.titleInput}/>
{/* <label> descripcion:</label><input type="Text" ref=
{this.descriptionInput}/> */}
<button type="submit" >Guardar</button>
</form>
</Fragment>
)
}
}
export default compose(graphql(updatePagPrincipal, {
name: 'updatePagPrinc'
}))(FormLogin);
----- index.js (Fragment of code)
............
const defaulState = {
pagPrincipal: {
__typename: 'PagPrincipal',
bienvenido: 'Bienvenido Hello!! estamos desde el local state',
descripcion: 'Este es el primer software web con tecnologia React,
ApolloGraphQl, Material-ui, node.js y mongoDB'
},
datosNumericos: {
__typename: 'DatosNumericos',
cantStock: 0
}
}
const stateLink = withClientState({
cache,
defaults: defaulState,
resolver: {
Mutation: {
updatePagPrinc: (_, { index, value }, { cache }) => {
console.log(index, value)
}
}
}
})
//Inicializando el ClienteApollo
const client = new ApolloClient({
//Unificando mi stado con el servidor
link: ApolloLink.from([
stateLink, //Unica Fuente de la verdad
httpLink //Servidor ApolloGraphQl
]),
cache
});