Without a sample query reference to tailor my answer, I think what you could leverage here are query fragments
to help with multiple templates.
For example:
fragment itemDetails on Item {
id
name
children{
children(includeTemplateIDs:"{GUID}"{
id
name
someotherfield
}
}
}
You can then leverage the template on your query
query GetPageContent($datasource: String!, $contextItem: String!) {
datasource(value: $datasource) {
...itemDetails
}
contextItem(value: $contextItem) {
...itemDetails
}
Ps: Please validate this syntax, just guiding on the approach here