-
-
Save kitten/3a9136fa731678838013292a32f7daaa to your computer and use it in GitHub Desktop.
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
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 |
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
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} | |
` |
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
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