Rule defined-types-are-used should detect reference loops
meiamsome opened this issue · comments
The following schema:
type Query {
field: Int!
}
type A {
b: B!
}
type B {
a: A!
}
Will currently not show any errors, despite types A and B being inaccessible types (Due to the cyclic dependencies they count as referenced)
The same is true for self-referential types:
type Query {
field: Int!
}
type A {
a: A!
}
Thanks for opening the issue @meiamsome. That's an interesting observation.
Today's defined-types-are-used
is indeed a bit naive in this respect.
If you have suggestions on how to improve this feel free to share them.
I get the feeling we'd have to walk the graph starting at Query
and Mutation
to determine if something is truly accessible or not. We'd have to consider interfaces in this too, i.e. if Node
is accessible then anything that implements Node
should be considered accessible.
Not sure how complex that'd be though. 🤔
Yes, I imagine it's something like a memoized BFS or DFS. I think also this rule does not currently obey inline lint-disable
s either, so that's something to take in to account I guess.
I would be interested in writing a PR to add this functionality in the near future, but I don't have any code yet - thought I'd at least document the issue to begin with.