What would a query and/or schema look like for the resolve argument info.fieldNodes.length > 1 (formaly info.fieldASTs)?
I can't find any reference to this and almost always see people doing info.fieldNodes[0] in resolve functions!
query OverlappingFieldsExample {
fieldA {
fieldB {
fieldC
}
}
...FragX
}
fragment FragX on Query {
fieldA {
fieldB {
fieldD
}
...FragY
}
}
fragment FragY on TypeA {
fieldB {
fieldE
}
}
If you were to look at info.fieldNodes in the fieldA field, you would see that info.fieldNodes.length === 2 and in fieldB info.fieldNodes.length === 3
This would produce a result like:
{
"data": {
"fieldA": {
"fieldB": {
"fieldC": "valueC",
"fieldD": "valueD",
"fieldE": "valueE"
}
}
}
}
If you see people writing info.fieldNodes[0] in resolve functions, then they will fail to properly support fragments that introduce overlapping fields!
Thanks for clearing that up!
I updated the graphql version to 0.9.1 the info.fieldNodes value is coming as undefined..
resolve(root, args, info, context) {
console.log(info.fieldNodes)
....}
can someone please advise on this
But it seems like code like this is ok:
Because overlapping fragments will only overlap if they have the same (or no) alias?
And presumably identical arguments?
Most helpful comment
If you see people writing
info.fieldNodes[0]in resolve functions, then they will fail to properly support fragments that introduce overlapping fields!