You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Currently, Graphene supports lazy type references (a string or a callable) in fields, input fields, and arguments. But there are other places where types are coupled that don't support it. From what I can tell, it's these cases:
Node types of a relay.Connection
Member types of a Union
Interfaces of an ObjectType or another Interface
Lazy references are useful for modelling schemas with circular dependencies across multiple Python modules without creating circular imports. But they're also useful for non-static schemas, which you might have when some relationships depend on configuration such as feature flags that aren't available at import time. For example, it's possible to do this:
Overall, it's a bit unintuitive that lazy references are allowed in some places but not others.
Describe the solution you'd like
Support lazy type references consistently across all type declarations, including in the three cases described above.
Describe alternatives you've considered
For circular imports, it's usually possible to break dependencies elsewhere in the chain where lazy references are already supported. Though there may be some more contrived cases that only involve the relationships described above, where this wouldn't be possible.
For dynamic schema parts, you could define all schema components at runtime rather than statically, but in practice I think the static approach is cleaner in most cases and makes it easier to distribute schema components across multiple modules.
Additional context
I don't expect the changes to be huge, they should be non-breaking, and I'm happy to contribute them if people find this useful.
Supporting node types for Connection should be easier. The node construction already supports lazy references, we'd just need to remove the hard-coded instance check and handle cases where the name isn't available here.
Interfaces are probably the biggest change since that will require the entire fields construction here to be moved to a property to be resolved lazily. Even then, it's conceptually very similar to the Union change above.
Is your feature request related to a problem? Please describe.
Currently, Graphene supports lazy type references (a string or a callable) in fields, input fields, and arguments. But there are other places where types are coupled that don't support it. From what I can tell, it's these cases:
relay.ConnectionUnionObjectTypeor anotherInterfaceLazy references are useful for modelling schemas with circular dependencies across multiple Python modules without creating circular imports. But they're also useful for non-static schemas, which you might have when some relationships depend on configuration such as feature flags that aren't available at import time. For example, it's possible to do this:
but we can't have this:
Overall, it's a bit unintuitive that lazy references are allowed in some places but not others.
Describe the solution you'd like
Support lazy type references consistently across all type declarations, including in the three cases described above.
Describe alternatives you've considered
For circular imports, it's usually possible to break dependencies elsewhere in the chain where lazy references are already supported. Though there may be some more contrived cases that only involve the relationships described above, where this wouldn't be possible.
For dynamic schema parts, you could define all schema components at runtime rather than statically, but in practice I think the static approach is cleaner in most cases and makes it easier to distribute schema components across multiple modules.
Additional context
I don't expect the changes to be huge, they should be non-breaking, and I'm happy to contribute them if people find this useful.
Connectionshould be easier. The node construction already supports lazy references, we'd just need to remove the hard-coded instance check and handle cases where the name isn't available here.Unionchange above.