Comments (9)
@dennisv you need to define your connection as a generic class, just like the original, and pass the NodeType
captured by the Generic in Connection
, just like this:
@gql.type
class CustomConnection(Generic[NodeType], Connection[NodeType]):
...
from strawberry-django-plus.
Thanks for the quick fix and feedback @bellini666 !
I got it to work by doing this:
from strawberry_django_plus.relay import NodeType
@gql.type
class CustomConnection(gql.Connection[NodeType]):
...
from strawberry-django-plus.
@K0Te I just made this change (0762f40) which got released in 1.23.
It allows to define a custom Connection
class for a Node
, similar to how graphene does. It also allows the Connection
to define a custom Edge
.
Do you think this is enough?
from strawberry-django-plus.
Hi @eloff ,
Currently you would need to implement your own Edge
and Connection
classes and override their logic. But I'm thinking in how to make that relay implementation more generic to allow things like what you want to do.
I'll probably take a look at this soon
from strawberry-django-plus.
Ok, good to know. I'll come up with a temporary workaround for now, but I'll revisit it when you close this ticket.
from strawberry-django-plus.
More generic connections would simplify migration from graphene-django
.
I am currently migrating project that uses multiple subtotals in connections.
For example:
class AccountClientConnection(Connection):
total_account_clients = graphene.Int()
total_active_account_clients = graphene.Int()
active_clients_count = graphene.Int()
Such use-case is trivial with graphene-django
connection_class
, but complicated with the current connection implementation in strawberry.
from strawberry-django-plus.
@bellini666 I'm trying to add some fields to a connection as well and can't seem to get it to work using CONNECTION_CLASS
Could it be that it is still always using the default Connection because of this line?
I'm trying it like this:
@gql.django.type(models.ObjectType)
class ObjectType(gql.Node):
name: gql.auto
@gql.type
class TestObjectTypeConnection(gql.Connection):
test: str = "test"
ObjectType.CONNECTION_CLASS = TestObjectTypeConnection
@gql.type
class ObjectTypeQuery:
@gql.connection
def object_types(
self,
...
) -> Iterable[ObjectType]:
...
But the test field does not show up in graphiql and returns "Cannot query field 'test' on type 'ObjectTypeConnection'."
from strawberry-django-plus.
Hey @dennisv ,
I just noticed that the field was not using the CONNECTION_CLASS
to create itself.
I just published the version 1.25.1, which should solve this issue. Can you please try to use it and confirm to me if it works?
from strawberry-django-plus.
@bellini666 I get a bit further now, but it's now throwing the following:
TypeError: <class '[...].TestObjectTypeConnection'> is not a generic class
from strawberry-django-plus.
Related Issues (20)
- AttributeError with strawberry-graphql 0.140.3: type object 'str' has no attribute 'resolve'
- Optimizier omits slicing of connection query set HOT 1
- DjangoOptimizerExtension not optimizing when fragments are used and field is queried twice HOT 2
- Regression with mypy from #137 HOT 1
- CUD mutations Input vs NodeInput HOT 5
- FieldError when using select_related with enable_only_optimization HOT 4
- matching query does not exist error when relational field does not exist HOT 1
- Query optimization based on type hints for non-model fields? HOT 4
- Prefetch related selects all the fields on the model instead of the ones specified in the gql query HOT 2
- Cursor Pagination without relay HOT 2
- HasObjPerm directive on a update mutation fails updating the cache, due to unhashable type OperationInfo HOT 7
- Optimizer causes duplicate query when filtering or paginating a related field HOT 11
- Non-obvious moments when overloading the Connection HOT 1
- InputMutation / Mutation not working with List return type HOT 3
- [Error] "children" lookup was already seen with a different queryset. You may need to adjust the ordering of your lookups. HOT 1
- auto creation of translated fields HOT 5
- pk required for mutations when handle_django_errors=False HOT 1
- [ERROR] Error in the project `default`: Invalid use of @refetchable on fragment HOT 3
- Update mutation fails with List HOT 4
- Non functional filters for django with relay. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strawberry-django-plus.