【问题标题】:GraphQLList and reactGraphQLList 和反应
【发布时间】:2016-07-13 19:49:11
【问题描述】:
我是 graphql 和 relay 的新手,但我做的一切都很好。
我尝试使用 graphql 查询来获取我的站点属性列表 (new GraphQLList(Property)),这里没有问题,所有属性都已获取,但我的 react 组件中的 props.properties 值如下:
{
__dataID__: "client:11752076762",
properties: {
__dataID__: "client:11752076762",
__status__: 4
},
__status__: 4
}
而不是获取的属性。
我很困惑,有什么问题? :(
【问题讨论】:
标签:
reactjs
graphql
relay
【解决方案1】:
尝试先在 graphiql 中运行查询。
...
.use('/graphql', graphqlHTTP({ schema, pretty: true, graphiql: true }))
然后尝试确认您在该查询中得到了您要查找的内容
【解决方案2】:
这可能与您的方式有关:
- 定义您的 GraphQL 架构(如果可能,请提供架构)
- 在 Relay.Container 中声明 GraphQL 数据片段要求(您需要明确声明所需的所有字段)
- 在 Relay.Route 中声明 GraphQL 路由
Relay.Container 示例:
Relay.createContainer(App, {
fragments: {
properties: () => Relay.QL`
fragment on Properties {
<IMPORTANT: fields that you want to be in props.properties should be here>
}
`
...
}
}
Relay.Route 示例:
Relay.Route {
static queries = {
properties: () => Relay.QL`
query {
properties
}
`,
}
}