import React, { Component } from 'react' import { graphql, gql, compose } from 'react-apollo' import { SINGLE_LINK_QUERY, UPDATE_LINK_MUTATION } from '../queries'; class UpdateLink extends Component { state = { ...this.props.findItem.Item, } saveToState = (e) => { let { name, value, type } = e.target; if (type === 'number') { value = parseInt(value); } this.setState({ [name]: value }); } render() { return (

Edit {this.props.id}

{ this.state.loading ? 'LOADING...' : 'Ready!' }
) } _createLink = async (e) => { e.preventDefault(); // pull the values from state const { description, title } = this.state const { id } = this.props; // create a mutation // TODO: handle any errors // turn loading on this.setState({ loading: true }); console.log(this.state); const res = await this.props.updateItem({ // pass in those variables from state variables: { ...this.state } }); this.setState({ loading: false }); } } const ComponentWithMutations = compose( // First, query for getting the link graphql(SINGLE_LINK_QUERY, { name: 'findItem', options: ({ id }) => ({ variables: { id } }) }), // Second, the mutation for updating the link graphql(UPDATE_LINK_MUTATION, { name: 'updateItem' }) )(UpdateLink); export default ComponentWithMutations;