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
@strawberry_django.type(models.User)
class User(relay.Node):
username: auto
first_name: auto
last_name: auto
email: auto
@strawberry.type
class UserQuery:
"""
User query class for GraphQL
"""
users: strawberry.relay.ListConnection[User] = strawberry_django.connection(
resolver=resolve_users
)
By default, I can query a specific User node using its Global ID like this -
But, how can I customize the behavior in a way that the node(...) should be able to accept other than the Global ID (like pk or any arbitrary field on all models in Django)
Hrm, for now you would probably need to subclass the node implementation and override it.
TBF, the implementation we have for node is pretty straight forward: it accepts a GlobalID, parses it (which comes in the form of <TypeName>:<type-id> and, in case of strawberry-django, it uses the TypeName to find which model to query and the type-id for the object id itself.
So in theory you could define your own node resolver, which returns a Node, accepts a GlobalID, and parse it the way you prefer.
Having said that, what is your use case here? Interested to understand if maybe we should allow customization for this
How can I build a custom node resolver for Global Object Identification with an XYZ unique identifier?
Consider that I defined the type(s) as below.
By default, I can query a specific
User
node using itsGlobal ID
like this -But, how can I customize the behavior in a way that the
node(...)
should be able to accept other than theGlobal ID
(likepk
or any arbitrary field on all models in Django)Example: (See
customUniqueID
parameter)or (see
anythingGoesHere(...)
query along withcustomUniqueID
)Is this doable?
The text was updated successfully, but these errors were encountered: