graphql-relay-py icon indicating copy to clipboard operation
graphql-relay-py copied to clipboard

Why are nodes optional?

Open pcraciunoiu opened this issue 5 years ago • 3 comments

I was trying to dig through this to figure it out, and I apologize if there's a good reason for this.

It seems to me that a paginated connection (e.g. DjangoConnectionField or DjangoFilterConnectionField) always has edges and nodes. What's the use case for these being nullable?

The reason I bring this up is because, when using TypeScript with the generated schema, it results in lengthy checks like this:

            {edges.map(edge => (
              <div>
                {edge &&
                  edge.node &&
                  edge.node.id (
                    ...<JSX here>

As far as I can tell this is set up here: https://github.com/graphql-python/graphql-relay-py/blob/master/graphql_relay/connection/connection.py#L44

Could there be required on edges/nodes? At least as an option it'd be a breaking change. Right now I'm not sure how to override this.

pcraciunoiu avatar Jun 04 '19 20:06 pcraciunoiu

@pcraciunoiu I think the location of this definition is in Graphene, but what you are claiming does not appear to be the case, at least not any more: https://github.com/graphql-python/graphene/blob/master/graphene/relay/connection.py#L96

markedwards avatar Apr 30 '20 14:04 markedwards

True! Is node required too? I can't tell by reading that.

pcraciunoiu avatar Apr 30 '20 14:04 pcraciunoiu

Not as far as I can tell:

https://github.com/graphql-python/graphene/blob/master/graphene/relay/connection.py#L79

If you follow the class, Field.required defaults to False, and it's not specified there. But I'm not very expert on the Graphene codebase so don't hold me to it :-)

markedwards avatar May 08 '20 14:05 markedwards