Consider the main SWAPI example for the reference implementation: https://github.com/graphql/swapi-graphql
// film.js
import PersonType from './person';
// person.js
import FilmType from './film';
That's all over the place. Are these circular deps an acceptable practice? Are there any good patterns for avoiding this? It seems bad to include problematic practices in the definitive demo for GraphQL.
In case of GraphQL it is not bad practice, they even prepared a solution for this situation. If you define
fields
attribute of some type, you can declare it as a functiongraphql-js
uses method calledresolveThunk
in order to handle thefields
attributes amongst other, and it's implementation is as followsAs you can see, it checks if the
thunk
(fields in this case) is function. If it is, returns it's result, otherwise returns thunk itself.