Calling getTypeByName directly or indirectly inside a type generator function is not allowed:
// BAD!
registerObjectType(
'Foo',
{},
() => {
const Bar = getTypeByName('Bar');
return {
fields: {
bar: {
type: Bar
}
}
}
},
''
);
it can only be called from within callbacks that that spec contains:
// Fine
registerObjectType(
'Foo',
{},
() => {
return {
fields() {
const Bar = getTypeByName('Bar');
return {
bar: {
type: Bar
}
};
}
}
},
''
);
The reason for this is it has the potential to trigger hard to debug and hard to reproduce cycles.
This PR enforces this rule by throwing if getTypeByName is called again when getTypeByName is currently running. This found the problem in 5 places in the core codebase, so I wouldn't be surprised if it also found issues with plugins. However, it's a net win because it should completely eradicate this class of error.
Thanks to @andreyobrezkov for bringing this to my attention.
Calling
getTypeByName
directly or indirectly inside a type generator function is not allowed:it can only be called from within callbacks that that spec contains:
The reason for this is it has the potential to trigger hard to debug and hard to reproduce cycles.
This PR enforces this rule by throwing if
getTypeByName
is called again whengetTypeByName
is currently running. This found the problem in 5 places in the core codebase, so I wouldn't be surprised if it also found issues with plugins. However, it's a net win because it should completely eradicate this class of error.Thanks to @andreyobrezkov for bringing this to my attention.