[Fixed]-Graphene Django and react-router-relay

1👍

I had this same issue and after a long search i finally found this answer
https://github.com/facebook/relay/issues/1558#issuecomment-297010663

Since relay 1 don’t support connections as root query. you should ad a viewer as a node interface to wrap your query.
So in your server main query (project/schema.py) you should add the following code:

class Query(project.threads.schema.Query, graphene.ObjectType):
   viewer = graphene.Field(lambda: Query)
   id = graphene.ID(required=True)

   def resolve_viewer(self, args, context, info):
    return info.parent_type

   def resolve_id(self, args, context, info):
      return 1

   class Meta:
      interfaces = (graphene.relay.Node,)

Now in you graphiql you can format your query like this:

query {
  viewer{
  allThreads(first:10) {
    edges {
      node {
        id
      }
    }
  }
}
}

In client side you can create your container like this:

export default Relay.createContainer(ThreadList, {
    fragments: {
        viewer: () => Relay.QL`
     fragment on Query {
          id
          allThreads(first:10){
            edges{
              node{
               id
               }
            }
          }
      }
    `,
    },
});

I hope this can help you

Leave a comment