英文:
bypass "nested" objects in GraphQL
问题
I have next gql fragment:
fragment PropertyInformationStateFragment on Property{
property_state{
data{
attributes{
state
description
}
}
}
}
and here is example of data returned:
"property_state": {
"data": {
"attributes": {
"state": "Tres bon état",
"description": "Tres bon état du bien immobilier"
}
}
}
Do somebody knows how to "bypass" this data
and attributes
objects?
Data returned I expect:
"property_state": {
"state": "blabla",
"description": "blabla"
}
What should I do?
英文:
I have next gql fragment:
fragment PropertyInformationStateFragment on Property{
property_state{
data{
attributes{
state
description
}
}
}
}
and here is example of data returned:
"property_state": {
"data": {
"attributes": {
"state": "Tres bon état",
"description": "Tres bon état du bien immobilier"
}
}
}
Do somebody knows how to "bypass" this data
and attributes
objects?
Data returned I expect:
"property_state": {
"state": "blabla",
"description": "blabla"
}
What should I do?
答案1
得分: 1
在这五年里,没有任何改变。仍然没有方法可以做到,我不认为将来会有改变。对此感到抱歉。
这是因为 GraphQL 只允许客户端定义响应中包含哪些字段或更改字段名称,但不允许更改响应结构。你的查询必须遵循服务器定义的类型结构。服务器只能以这个定义的结构返回数据,但你现在要求的是以完全不同的结构返回数据。
你可以在客户端手动将其转换为你想要的结构,这应该非常容易。
英文:
Nothing changed in these 5 years. There are still no ways to do it and I don't think it will have in the future. Sorry about that.
It is because GraphQL only allows client to define which fields to be included in the response or changing the field name but not allow change the response structure. Your query must following the type structure defined by the server. The server can only return you the data in this defined structure but what you are asking now is to return the data in a total different structure.
What you can do is to convert it to the structure that you want manually in the client side which should be a piece of cake.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论