Last active
August 31, 2020 06:42
-
-
Save kjmczk/38afb8d8a91cfc449257c823b6eb1706 to your computer and use it in GitHub Desktop.
pages/new.js - Next Fauna Auth - Medium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// pages/new.js | |
import useSWR from 'swr'; // add | |
const New = ({ token }) => { | |
const { data: user } = useSWR('/api/user'); // add | |
... | |
const onSubmit = handleSubmit(async ({ task }) => { | |
... | |
// update | |
const mutation = gql` | |
mutation CreateATodo($task: String!, $owner: ID!) { | |
createTodo( | |
data: { task: $task, completed: false, owner: { connect: $owner } } | |
) { | |
task | |
completed | |
owner { | |
_id | |
} | |
} | |
} | |
`; | |
// add | |
const variables = { | |
task, | |
owner: user && user.id, | |
}; | |
try { | |
await graphQLClient(token).request(mutation, variables); // update | |
... | |
} | |
}); | |
... | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment