There are publications and tags with many-to-many relations. Here's schema.gql
:
input GetPublicationsDto {
cursor: Int
take: Int
tagIds: [Int!]
tagId: Int
...
}
input GetTagsForDto {
tagIds: [Int!]
tagId: Int
}
type Query {
publications(data: GetPublicationsDto!): [Publication!]!
tagsFor(data: GetTagsForDto!): [Tag!]!
}
We see that GetPublicationsDto
extends GetTagsForDto
.
Suppose we want to get publications by some tagId and this tag data in a single request. Here's the query:
query PublicationsWithTags($data: GetPublicationsDto!) {
publications(data: $data) {
...PublicationEntry
}
tagsFor(data: $data) {
...TagEntry
}
}
This code fails to compile. The error is Variable "$data" of type "GetPublicationsDto!" used in position expecting type "GetTagsForDto!".
IMHO this code has to work, but the error is clear. It wants different data to be provided to tagsFor
query. But how to extract specific key from $data
?
I tried
query PublicationsListWithTags($data: GetPublicationsDto!) {
publications(data: $data) {
...PublicationListEntry
}
tagsFor(data: { tagId: $data.tagId }) {
id
name
}
}
It does not compile either, Cannot parse the unexpected character "."
. What is the right way to extract key from $data
and pass it into the tagsFor
query?
TWIMC, the solution for the provided example is trivial,
query PublicationsWithTags($data1: GetPublicationsDto!, $data2: GetTagsForDto) {
publications(data: $data1) {
...PublicationEntry
}
tagsFor(data: $data2) {
...TagEntry
}
}