Closed lautarodapin-magoya closed 5 months ago
Hi @lautarodapin-magoya ! If you can create a PR with a test reproducing the error and the fix in the code (I guess it would be a ternary checking if field_node.name
is a string), then I would be more than welcome to merge that PR and release a new version. Not sure why name
is a string in this case, maybe because of a change in graphene versions. Let me know if you need any help with this.
@tfoxy sorry for the late resopnse i got switch from the project and now i got it back
# models.py
class Account(UUIDTimeStampedModel):
pass
class Contact(UUIDTimeStampedModel):
account = models.ForeignKey(Account, models.CASCADE, related_name='contacts')
class Opportunity(UUIDTimeStampedModel):
contact = models.ForeignKey(Contact, models.CASCADE, related_name='opportunities')
# schema.py
class OpportunityType(DjangoObjectType):
class Meta:
model = Opportunity
class ContactType(DjangoObjectType):
class Meta:
model = Contact
class AccountType(DjangoObjectType):
opportunities = graphene.List(OpportunityType, required=True)
class Meta:
model = Account
def resolve_opportunities(self, info):
qs = OpportunityModel.objects.filter(contact__in=self.contacts.all())
return gql_optimizer.query(qs, info)
this is the minimal code this is the info field at the resolver point
GraphQLResolveInfo(field_name='opportunities', field_nodes=[FieldNode at 495:540], return_type=<GraphQLNonNull <GraphQLList <GrapheneObjectType 'OpportunityType'>>>, parent_type=<GrapheneObjectType 'AccountType'>, path=Path(prev=Path(prev=Path(prev=Path(prev=Path(prev=Path(prev=Path(prev=None, key='supplyOrders', typename='Query'), key='items', typename='SupplyOrderListType'), key=0, typename=None), key='quote', typename='SupplyOrderType'), key='contact', typename='QuoteType'), key='account', typename='ContactType'), key='opportunities', typename='AccountType'), schema=<graphql.type.schema.GraphQLSchema object at 0xffff5b8ab990>, fragments={}, root_value=None, operation=OperationDefinitionNode at 0:749, variable_values={}, context=<WSGIRequest: POST '/graphql/'>, is_awaitable=<function is_awaitable at 0xffff82620fe0>)
I guess doing this should be almost the same
@gql_optimizer.resolver_hints(prefetch_related="opportunities")
def resolve_opportunities(...): ...
We are also interested in this change! (I can see we pinned GraphQL Core 19 months ago)
But I think it is already fixed by https://github.com/tfoxy/graphene-django-optimizer/commit/618f8190e804cbb6552bbbe779ce9d7b90669c20
Until there is a proper release, you can target the commit for installation I guess
@martinlehoux thanks, i will check that!
@martinlehoux now it works! thank you!
This is the info context
And i'm getting the error when the optimizer tries to get the field def
and it gets the error in the first linne of the function due to
field_node
is now a string