mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
5ede8c9dc3
* More complete with-apollo-and-redux example with dynamic post route * Removed commented out code
42 lines
893 B
JavaScript
42 lines
893 B
JavaScript
import React from 'react'
|
|
import { gql, graphql } from 'react-apollo'
|
|
import PostUpvoter from './PostUpvoter'
|
|
|
|
function Post ({ id, data: { loading, error, Post } }) {
|
|
return (
|
|
<section>
|
|
<div key={Post.id}>
|
|
<h1>{Post.title}</h1>
|
|
<p>ID: {Post.id}<br/>URL: {Post.url}</p>
|
|
<PostUpvoter id={Post.id} votes={Post.votes} />
|
|
</div>
|
|
</section>
|
|
)
|
|
}
|
|
|
|
const post = gql`
|
|
query post($id: ID!) {
|
|
Post(id: $id) {
|
|
id
|
|
title
|
|
votes
|
|
url
|
|
createdAt
|
|
}
|
|
}
|
|
`
|
|
|
|
|
|
// The `graphql` wrapper executes a GraphQL query and makes the results
|
|
// available on the `data` prop of the wrapped component (PostList)
|
|
// Tip: ownProps is parent component's props
|
|
export default graphql(post, {
|
|
options: (ownProps) => {
|
|
return {
|
|
variables: {
|
|
id: ownProps.id
|
|
}
|
|
}
|
|
}
|
|
})(Post)
|