中继现代片段错误(期望对象包含数据..)



我正在使用Relay和django-graphene版本2。国家.js正在呈现国家/地区的 av 列表。

使用片段我得到这个错误: 警告:RelayModernSelector:预期对象包含片段Country_country的数据,{"node":{"__fragments":{"Country_country":{}},"__id":"Q291bnRyeVR5cGU6MQ=="}}。确保父操作/片段包含片段...Country_country,没有@relay(mask: false)

QueryRenderer 返回正确的国家/地区列表,无需Country_country,只需输入变量名称即可。

<QueryRenderer
environment={environment}
query={graphql`query CartContainerQuery {
viewer {
id
countries(first: 3) {
edges {
node {
...Country_country
}
}
pageInfo {
startCursor
endCursor
}
}
}
}`}
variables={{}}
render={({error, props}) => {
if (error) {
console.log(error)
return <div>Error!</div>;
}
if (!props) {
return <div>Loading...</div>;
}
return (
<div>
{console.log(props)}
<Country country={props.viewer.countries.edges} />
</div>
);
}}
/>

我在Contry容器上的片段:

export default createFragmentContainer(
Country,
graphql`
fragment Country_country on CountryType @relay(plural: true) {
id
name
}
`
)

石墨烯架构:

class CountryType(DjangoObjectType, model=Country):
class Meta:
interfaces= (relay.Node,)
filter_fields = ['name', 'id']
class Viewer(graphene.ObjectType):
class Meta:
interfaces = [relay.Node, ]
countries = DjangoFilterConnectionField(CountryType)
country = graphene.List(CountryType)
def resolve_country(self, info, **kwargs):
return Country.objects.all()
def resolve_countries(self, info, **kwargs):
return Country.objects.all()
class Query(graphene.ObjectType):
viewer = graphene.Field(Viewer)
node = relay.Node.Field()
def resolve_viewer(self, info):
return Viewer()

如果我在查询渲染器中尝试此查询,它也可以正常工作:

query={graphql`query CartContainerQuery {
viewer {
id
country {
...Country_country
}
}
}`}

我是否错误地使用了DjangoFilterConnectionField?

正如我现在所知道和测试的那样,你的石墨烯方面是好的,错误来自ReactJS方面,这意味着你正在使用DjangoFilterConnectionField。

我对此有很多研究,但由于我没有完全看到您的 React 代码,我有点怀疑。 无论如何,正如我在此示例(查询,片段(中看到的那样,您用错了:

<Country country={props.viewer.countries.edges} />

你应该像这样使用它:

<Country country={props.viewer.countries} />

据我了解,您需要将查询的对象传递给孩子

最新更新