reactjs - 中继:graphql标签中的片段名称必须以模块名称为前缀
问题描述
我正在尝试遵循https://www.howtographql.com/react-relay上的教程,但尝试针对非常相似的项目对其进行调整。但是,当我尝试调用编译器时出现错误:
Parse error: Error: RelayFindGraphQLTags: Fragment names in graphql tags must be prefixed with the module name. Got `ListItem_data` in module `listItem`. in "components/showAll/list-item.js"
简化的文件夹结构:
|enviornment.js
|src
|_showAll
|_ list-item.js
|_ list.js
|_ show-all.js
Schema is in root folder
简化代码:
----show-all.js(入口点)
import {
QueryRenderer,
graphql
} from 'react-relay';
import environment from '../../Enviornment';
const ShowAllPageQuery = graphql`
query ShowAllPageQuery {
viewer {
...List_viewer
}
}
`
const ShowAll = (props) => {
return (
<QueryRenderer
environment={environment}
query={ShowAllPageQuery}
render={({error, props}) => {
if(error) {
return <div>{error.message}</div>
} else if(props) {
return <List viewer={props.viewer} />
}
return <div>Loading</div>
}}
/>
)}
export default ShowAll
----list.js(showAll 的子级)
import {
createFragmentContainer,
graphql
} from 'react-relay'
const List = (props) => {
return (
<>
{props.viewer.translations.edges.map(({node}, index) => {
return(
<ListItem color={index % 2 == 0 ? 1 : 0} key={node.__id} data={node} />
)
})}
</>
)
}
export default createFragmentContainer(List, graphql`
fragment List_viewer on Viewer {
translations(first: 10, orderBy: createdAt_DESC) @connection(key: "List_translations", filters:[]) {
edges {
node {
...ListItem_data
}
}
}
}
`)
----list-item.js
import {
createFragmentContainer,
graphql
} from 'react-relay'
const ListItem = (props) => {
// const link = `/showall/${props.data.planCode}`
return (
<ListItemWrap color={props.color}>
<Link to={link}>
<Item>
<p>{props.data.planCode}</p>
<p>{props.data.longName}</p>
<p>{props.data.shortName}</p>
</Item>
</Link>
</ListItemWrap>
)
}
export default createFragmentContainer(ListItem, graphql`
fragment ListItem_data on ListItem {
id
planCode
longName
shortName
}
`)
架构:
type Mutation {
createTranslation(planCode: String!, longName: String!, shortName: String!): Translation
updateTranslation(id: ID!, planCode: String!, longName: String!, shortName: String!): String
deleteTranslation(planCode: String!): String
}
type Query {
translations: [Translation]
translation(planCode: String!): Translation
}
type Translation {
id: ID
planCode: String
longName: String
shortName: String
}
我在这里做错了吗?
解决方案
如果我没记错的话,我认为编译器是区分大小写的。所以你要么必须:
- 将您的文件重命名,例如,将 list-item.js重命名为ListItem.js
- 或尝试重命名片段,例如
ListItem_data
,list-item_data
我更喜欢选项#2
推荐阅读
- docker - 在 Docker 映像中处理包管理器安全更新的方法
- java - Thymeleaf or JSP: which is better with Spring Boot?
- android - How to add imageviews to constraint layout
- python-3.x - 如何平滑二值图像中的轮廓/边界?
- amazon-web-services - AWS:使用 EC2 实例创建来触发 lambda
- javascript - 使用 webpack 和 babel-loader 高效导入导出模块 - 摇树不工作
- command-line - Mcafee Commadline 工具 (vscl) 需要很长时间才能加载
- javascript - Changing a list of element from Selenium in Python
- c - How to print binary tree?
- javascript - 超链接中的 javascript 引用?