In GraphQL, can you change the structure of the output in an alias?

左心房为你撑大大i 提交于 2021-01-20 09:04:24

问题


Let's say I've got a GraphQL query that looks like this:

query {
  Todo {
    label
    is_completed
    id
  }
}

But the client that consumes the data from this query needs a data structure that's a bit different- e.g. a TypeScript interface like:

interface Todo {
  title: string  // "title" is just a different name for "label"
  data: {
    is_completed: boolean
    id: number
  }
}

It's easy enough to just use an alias to return label as title. But is there any way to make it return both is_completed and id under an alias called data?


回答1:


There is no way to do that. Either change the schema to reflect the client's needs or transform the response after it is fetched on the client side.



来源:https://stackoverflow.com/questions/60561282/in-graphql-can-you-change-the-structure-of-the-output-in-an-alias

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!