This file contains hidden or 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
type User { | |
id: ID! | |
email: String! | |
posts: [Post!]! | |
} | |
type Post { | |
id: ID! | |
title: String! | |
content: String | |
} |
This file contains hidden or 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
type Mutation { | |
changePostTitle(postId: ID!, title:String!): Post | |
} |
This file contains hidden or 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
const titleMutation = graphql` | |
mutation MyComponentTitleMutation( | |
$postId: ID! | |
$title: String! | |
) { | |
changePostTitle(postId: $postId, title: $title) { | |
id | |
title | |
} | |
} |
This file contains hidden or 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
type Mutation { | |
deletePostContent(postId: ID!): Boolean | |
} |
This file contains hidden or 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
const contentMutation = graphql` | |
mutation MyComponentContentMutation( | |
$postId: ID! | |
) { | |
deletePostContent(postId: $postId) { | |
id | |
content | |
} | |
} | |
`; |
This file contains hidden or 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
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | |
const makeStyles = (theme: Theme) => | |
StyleSheet.create({ | |
url: { | |
color: theme.link, | |
textDecorationLine: 'underline', | |
}, | |
}); | |
This file contains hidden or 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
// Original demo. | |
async function renderReactTree(res, props) { | |
await waitForWebpack(); | |
const manifest = readFileSync( | |
path.resolve(__dirname, '../build/react-client-manifest.json'), | |
'utf8' | |
); | |
const moduleMap = JSON.parse(manifest); | |
pipeToNodeWritable(React.createElement(ReactApp, props), res, moduleMap); | |
} |
This file contains hidden or 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
function sendResponse(req, res, component, props = null) { | |
props = props ?? {}; | |
renderReactTree(res, component, props); | |
} | |
router.get('/', function(req, res) { | |
sendResponse(req, res, Home); | |
}); | |
router.get('/posts', (req, res) => { |
This file contains hidden or 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
// Original | |
export function useServerResponse(location) { | |
const key = JSON.stringify(location); | |
const cache = unstable_getCacheForType(createResponseCache); | |
let response = cache.get(key); | |
if (response) { | |
return response; | |
} | |
response = createFromFetch( | |
fetch('/react?location=' + encodeURIComponent(key)) |
This file contains hidden or 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 function useCacheInvalidate() { | |
const cache = unstable_getCacheForType(createResponseCache); | |
return (key) => { | |
cache.delete(key); | |
}; | |
} |
OlderNewer