Skip to content

Instantly share code, notes, and snippets.

@kjmczk
Last active August 31, 2020 06:42
Show Gist options
  • Save kjmczk/38afb8d8a91cfc449257c823b6eb1706 to your computer and use it in GitHub Desktop.
Save kjmczk/38afb8d8a91cfc449257c823b6eb1706 to your computer and use it in GitHub Desktop.
pages/new.js - Next Fauna Auth - Medium
// 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