question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Share fields between mutation input and relay Node

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
syrusakbarycommented, Sep 11, 2016

This is now fixed in the master branch (1.0.dev version in PyPI), as you can make reusable AbstractType for sharing fields.

Closing the issue! 😃

1reaction
syrusakbarycommented, Feb 5, 2016

Will work on that soon! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Relay's Input Object Mutations | egghead.io
This standard includes a way for mutations to accept and emit an identifier string, allowing Relay to track mutations and responses. In this...
Read more >
Robust GraphQL mutations the Relay way - LogRocket Blog
This post walks you through the Relay API spec and identifies best practices to help you create solid API designs for GraphQL mutations....
Read more >
Mutations | Relay
updater : Function used to update the local in-memory store based on the real server response from the mutation. If updater is not...
Read more >
What type of Relay mutator configuration is appropriate for ...
Finally, add the GraphQL mutation as 'addAccount' to your schema mutation fields, which is referenced by the client side mutation. Share.
Read more >
GraphQL Mutations with React & Relay Tutorial
This is a standard setup for a React component with two input fields where users can provide the url and description of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found