console.log('resp',data)// logs undefined and then {"Movie":{"releaseDate":"2010-08-28T20:00:00.000Z","actors":[{"name":"Leonardo DiCaprio"},{"name":"Ellen Page"},{"name":"Tom Hardy"},{"name":"Joseph Gordon-Levitt"},{"name":"Marion Cotillard"}]}}
return(
<>
<divclassName="App">{JSON.stringify(data)}</div>
<buttondisabled={loading}onClick={refetch}>
refetch
</button>
</>
)
}
Sample mutation
const[{loading},execute]=useMutation(gql`
mutation($id: Float!, $name: String!) {
book(bookId: $id) {
edit(name: $name) {
id
name
}
}
}
`)
return(
<button
disabled={loading}
onClick={async()=>{
constdata=awaitexecute({
id:2,
name:'Lord of the Rings III'
})
console.log('App -> mutated',data)
}}
>
mutate
</button>
)
Is this a replacement for apollo/relay?
No, it's only suitable for small and simple apps-see FAQ on graphql-request. It doesn't have any caching, no links, doesn't support SSR, no complex features.