Share fields between mutation input and relay Node
See original GitHub issueI want to share fields between a relay Node and a mutation input as shown in this example: http://graphene-python.org/playground/?schema=import%2520collections%250A%250Aimport%2520graphene%250Afrom%2520graphene%2520import%2520relay%250A%250Aclass%2520SharedUserFields(graphene.ObjectType)%253A%250A%2520%2520%2520%2520first_name%2520%253D%2520graphene.String()%250A%2520%2520%2520%2520last_name%2520%253D%2520graphene.String()%250A%250Aclass%2520User(relay.Node)%253A%250A%2520%2520%2520%2520user_id%2520%253D%2520graphene.ID()%250A%250A%2520%2520%2520%2520%2540classmethod%250A%2520%2520%2520%2520def%2520get_node(cls%252C%2520user_id)%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520user%2520%253D%2520%257B'user_id'%253A%2520'1'%257D%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520User(**user)%250A%250AUser.extend_fields(%255BSharedUserFields%255D)%250A%250Aclass%2520UpdateCustomer(relay.ClientIDMutation)%253A%250A%2520%2520%2520%2520class%2520Input(SharedUserFields)%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520pass%250A%2509%250A%2520%2520%2520%2520user%2520%253D%2520graphene.Field(User)%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520def%2520mutate_and_get_payload(cls%252C%2520mutation_input%252C%2520info)%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520%2523%2520update%2520stuff%2520here%250A%2520%2520%2520%2520%2520%2520%2520%2520return(User(first_name%253D'Mutated%2520first_name'))%250A%2520%2520%2520%2520%250Aclass%2520Query(graphene.ObjectType)%253A%250A%2520%2520%2520%2520user%2520%253D%2520graphene.Field(User)%250A%2520%2520%2520%2520%250A%2520%2520%2520%2520def%2520resolve_user(self%252C%2520args%252C%2520info)%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520user%2520%253D%2520%257B%27user_id%27%253A%2520%271%27%257D%250A%2520%2520%2520%2520%2520%2520%2520%2520return%2520User(**user)%250A%250Aschema%2520%253D%2520graphene.Schema(query%253DQuery)%250A&query=query%2520testQuery%2520%257B%250A%2520%2520user%2520%257B%250A%2520%2520%2520%2520firstName%250A%2520%2520%2520%2520%257D%250A%257D
For some reason extend_fields
does not work on the playground but maybe the graphene version is outdated.
But how would it be possible to share graphene fields between the User
relay Node and the UpdateCustomerInput
to reduce duplication?
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (8 by maintainers)
Top GitHub Comments
This is now fixed in the master branch (
1.0.dev
version in PyPI), as you can make reusableAbstractType
for sharing fields.Closing the issue! 😃
Will work on that soon! 😃