Better relay types

This commit is contained in:
Chi Vinh Le
2018-07-04 15:01:47 -03:00
parent 95bf54366c
commit 9f79ee1c6d
8 changed files with 42 additions and 35 deletions
@@ -15,8 +15,8 @@ const AppContainer: StatelessComponent<InnerProps> = props => {
return <App {...props.data} />;
};
const enhanced = withFragmentContainer<{ data: Data }>(
graphql`
const enhanced = withFragmentContainer<{ data: Data }>({
data: graphql`
fragment AppContainer on Query
@argumentDefinitions(
assetID: { type: "ID!" }
@@ -29,8 +29,8 @@ const enhanced = withFragmentContainer<{ data: Data }>(
...StreamContainer_asset
}
}
`
)(AppContainer);
`,
})(AppContainer);
export type AppContainerProps = PropTypesOf<typeof enhanced>;
export default enhanced;
@@ -16,8 +16,8 @@ const AssetListContainer: StatelessComponent<InnerProps> = props => {
return <AssetList assets={assets} />;
};
const enhanced = withFragmentContainer<{ assets: Data }>(
graphql`
const enhanced = withFragmentContainer<{ assets: Data }>({
assets: graphql`
fragment AssetListContainer_assets on AssetsConnection {
edges {
node {
@@ -26,8 +26,8 @@ const enhanced = withFragmentContainer<{ assets: Data }>(
}
}
}
`
)(AssetListContainer);
`,
})(AssetListContainer);
export type AssetListContainerProps = PropTypesOf<typeof enhanced>;
export default enhanced;
@@ -14,16 +14,16 @@ const CommentContainer: StatelessComponent<InnerProps> = props => {
return <Comment {...rest} {...props.data} />;
};
const enhanced = withFragmentContainer<{ data: Data }>(
graphql`
const enhanced = withFragmentContainer<{ data: Data }>({
data: graphql`
fragment CommentContainer on Comment {
author {
username
}
body
}
`
)(CommentContainer);
`,
})(CommentContainer);
export type CommentContainerProps = PropTypesOf<typeof enhanced>;
export default enhanced;
@@ -45,26 +45,28 @@ class StreamContainer extends React.Component<InnerProps> {
}
const enhanced = withPaginationContainer<{ asset: Data }, InnerProps>(
graphql`
fragment StreamContainer_asset on Asset
@argumentDefinitions(
count: { type: "Int", defaultValue: 5 }
cursor: { type: "Cursor" }
orderBy: { type: "COMMENT_SORT", defaultValue: CREATED_AT_DESC }
) {
id
isClosed
comments(first: $count, after: $cursor, orderBy: $orderBy)
@connection(key: "Stream_comments") {
edges {
node {
id
...CommentContainer
{
asset: graphql`
fragment StreamContainer_asset on Asset
@argumentDefinitions(
count: { type: "Int", defaultValue: 5 }
cursor: { type: "Cursor" }
orderBy: { type: "COMMENT_SORT", defaultValue: CREATED_AT_DESC }
) {
id
isClosed
comments(first: $count, after: $cursor, orderBy: $orderBy)
@connection(key: "Stream_comments") {
edges {
node {
id
...CommentContainer
}
}
}
}
}
`,
`,
},
{
direction: "forward",
getConnectionFromProps(props) {