问题
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