-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Relay Modern Example (#1757) #2773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks! |
@petrvlcek It doesn't work. Probably wrong path somewhere. Can you fix it please? Also, I don't understand why you chose unfetch, it seems to by only browser polyfil. |
@steida I forgot to add |
And Unfetch does work for Node.js? Anyway, what is the compelling reason to not use isomorphic fetch? |
It works for Node.js. I've been using it elsewhere and didn't think about it. I have no problem changing that to Is the example working after downloading schema introspection data with |
@steida isomorphic-unfetch does work on the server. Uses node-fetch under the hood, same as isomorphic-fetch 👌 |
* Add examples/with-redux-code-splitting. (#2721) * #1757 Relay Modern Example (#2696) * Add ReasonML example (#2640) * Add ReasonML example * Add a gitignore specifically for the reasonml example * Allow custom className for <Main /> (#2802) * 3.0.2 * Remove beta information from the README. * 3.0.3 * Remove unnecessary lookup in example with emotion (#2731) * Document SCSS/Less (#2742) * Document SCSS/Less * Add missing word * Add docs for examples dir * Add extra example * uppercase J * Add with pkg example (#2751) * Add custom server micro example (#2750) * Ease running multiple examples at the same time with process.env.PORT (#2753) * Add line-height rule for error page h2 (#2761) * Add support for fetching multiple translation files (#2743) * Add support for fetching multiple translation files * Cleanup * Clear missed interval (#2611) * clear missed interval * remove trailing whitespace * Relay Modern Example (#1757) (#2773) * Simplification of Relay Modern Example (#1757) (#2776) * Use deterministic names for dynamic import (#2788) * Always use the same name for the same dynamic import. * Add unit tests for the modulePath generation. * Allow tests to run correctly on Windows. * Make the chunk name a bit pretty. * Fix tests to run on Windows. * 3.0.4 * Revert "Make the chunk name a bit pretty." (#2792) This reverts commit 0c9e8cf. * 3.0.5 * Use _ as the divider for dynamic import name splitter. (#2793) Using - gives us some weird webpack errors. * 3.0.6 * next/dynamic Error Message Tweaks (#2798) * Fixed issue (#2804) #2800 * docs(material-ui): move the source code to Material-UI repository (#2808)
I'm trying to inject a postId variable into a fragmentContainer. That variable does not pass at all, even when applying all kind of solutions found on stackoverflow (these don't use nextjs, and use a router, which may be the difference with my project). I've started the project with the with-relay-modern example. The variable $postId doesn't inject properly, so I used Any idea how to achieve this? Is this related to how SSR works? Deleting **defaultValue: "UG9zdDoy" ** and re-compiling gives the following error: The page - singlePost.jsimport React, { Component } from 'react'
import { graphql } from 'react-relay'
import withData from '_libs/withData'
import PostDetail from '_components/post_page/PostDetail'
import App from '_components/App'
class PostsPage extends Component {
static displayName = `PostsPage`
static getInitialProps ({ query }) {
return { query }
}
render (props) {
const { viewer } = this.props
return (
<div>
{viewer ? <PostDetail {...this.props}
postId={this.props.url.query.postId}
viewer={viewer}
relay={this.props.environment} /> : 'no viewer'}
</div>
)
}
}
export default withData(PostsPage, {
query: graphql`
query singlePost_Query {
viewer {
...PostDetail_viewer
}
}`,
}) The component - postDetail.jsimport React from 'react'
import PropTypes from 'prop-types'
import { createFragmentContainer, graphql } from 'react-relay'
const PostDetail = (props, {viewer}) => {
return (
<div>
post
</div>
)
}
PostDetail.propTypes = {
viewer: PropTypes.shape({
post: PropTypes.shape({
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
image: PropTypes.string.isRequired,
creator: PropTypes.shape({
firstName: PropTypes.string.isRequired,
lastName: PropTypes.string.isRequired,
}).isRequired,
}),
}).isRequired,
}
// postId only works with defaultValue, but I need to get it from props.
export default createFragmentContainer(
PostDetail,
graphql`
fragment PostDetail_viewer on Viewer
@argumentDefinitions(
postId: {type: "String!", defaultValue: "UG9zdDoy"},
)
{
post (postId: $postId) {
title
description
image
creator {
firstName
lastName
}
}
}
`,
) |
I don't remember the exact syntax, but the way I made parameters work for a fragment was to use query singlePost_Query($postId: String!) {
viewer {
...PostDetail_viewer @arguments(postId: $postId)
}
} And then you pass your postId param to your withData. If this doesn't work for you, I'll try to find you a more complete example, but my code is slightly more complicated than that. |
@AugustinLF many thanks for your answer. |
Ok got it, just in case someone needs this in the future: // singlePost.js
query singlePost_Query($postId: String!) {
viewer {
...PostDetail_viewer @arguments(postId: $postId)
}
} Then in withData.js, add postId in the variables if (options.query) {
const variables = {
postId: ctx.query.postId
}
queryProps = await fetchQuery(environment, options.query, variables)
queryRecords = environment.getStore().getSource().toJSON()
} |
Hi! I'm having a little trouble to get the errors of a query using this example. The errors returned by the query are not available on the component props. // query response
{
data: { foo: null },
errors: [
{ message: 'example' },
]
} // component render method
render () {
console.log(this.props.foo) // null
console.log(this.props.errors) // undefined :(
} |
@timneutkens Re-created PR to be merged to
master
branch this time.