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.

Add Documentation for Relay Edge implementation

See original GitHub issue

In the Relay mutation docs, performing RANGE_ADD requires that the new edge created by the mutation is provided in the payload.

I do not know how to provide the correct cursor/Edge construction within the relay.ClientIDMutation subclass.

The following code I wrote:

new_object_edge = graphene.Field('ObjectEdge')

I believed would solve my issue, with a proper resolve_new_object_edge(...) resolver.

However, my resolver cannot reference the relay.ConnectionField that is specified on one of the other object types in my mutation, since it only has the context of my (in this case, Django) objects.

I experimented with relay.Edge.for_node(SomeObjectType) as well but all of the solutions I have tried so far modify the schema correctly but cannot return the appropriate Edge.

The implementation of this scenario in javascript can be found here in the Relay examples directory.

Any idea of a best approach? I can take this question to stack overflow, but felt that people using Relay & Graphene would enjoy seeing an example solution in the docs.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:28 (15 by maintainers)

github_iconTop GitHub Comments

13reactions
rangermeiercommented, Oct 26, 2017

Since I struggled a lot to expose a newly created item as edge, here is a complete example using Graphene 2.0, building on the suggestions from @mickeyinfoshan and @varuna82. Hope this is of some help:

import graphene
from graphene import relay
from graphene_django import DjangoObjectType
from graphql_relay.connection.arrayconnection import offset_to_cursor
from myapp import models

class Topic(DjangoObjectType):
    class Meta:
        model = models.Topic
        interfaces = (relay.Node, )

TopicEdge = Topic._meta.connection.Edge

class CreateTopic(relay.ClientIDMutation):
    class Input:
        title = graphene.String(required=True)

    topic = graphene.Field(Topic)
    topic_edge = graphene.Field(TopicEdge)

    @classmethod
    def mutate_and_get_payload(cls, root, info, **input):
        topic = models.Topic.objects.create(title=input['title'], created_by=user)
        edge = TopicEdge(cursor=offset_to_cursor(0), node=topic)
        return CreateTopic(topic=topic, topic_edge=edge)
1reaction
reinierpdcommented, Jun 14, 2017

I’m using graphene-django 1.3 and neither relay.types.Edge or relay.Edge exist. Any idea from where can i import Edge ?? @mickeyinfoshan

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quick Start Guide - Relay
In this guide we are going to give a brief overview of how Relay works and how to use it, using as reference...
Read more >
Explaining GraphQL Connections - Apollo GraphQL Blog
The circles in the graph are called “nodes” and the lines of the graph are called “edges.” An edge is a line that...
Read more >
Relay - graphql-python
First of all, let's implement our link query using Relay. You will write all the following code in a new schema file, keeping...
Read more >
Class: GraphQL::Relay::BaseConnection
An opaque operation which returns a connection-specific cursor. Raises: (GraphQL::RequiredImplementationMissingError). [View source] ...
Read more >
using subscriptions to update data in relay modern
The schema follows Relay's GraphQL specification, implementing nodes, cursors, and edges to standardize our data for Relay.
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