Skip to content

Instantly share code, notes, and snippets.

@kitten

kitten/detail.js Secret

Created May 10, 2018 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitten/3a9136fa731678838013292a32f7daaa to your computer and use it in GitHub Desktop.
Save kitten/3a9136fa731678838013292a32f7daaa to your computer and use it in GitHub Desktop.
import { Cache, Connect, query, fragment } from 'urql'
import { todo, todoFragment } from './gql.js'
const Detail = ({ id }) => (
<Connect query={query(todos)}>
{({ loading, data: fetchedData }) => (
<Cache query={fragment(todoFragment, { id })}>
{({ data: cachedData }) => {
const data = loading ? cachedData : fetchedData;
return (/* ... */)
}}
</Cache>
)}
</Connect>
)
export default Detail
export const todoFragment = `
fragment TodoFragment {
id
text
isDone
createdAt
}
`
export const todos = `
query Todos {
todos {
...TodoFragment
}
}
${todoFragment}
`
export const todo = `
query Todo($id: ID!) {
todo(id: $id) {
...TodoFragment
}
}
${todoFragment}
`
import { Connect, query } from 'urql'
import { todos } from './gql.js'
const List = () => (
<Connect query={query(todos)}>
{/* ... */}
</Connect>
)
export default List
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment