Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are nodes optional? #19

Open
pcraciunoiu opened this issue Jun 4, 2019 · 3 comments
Open

Why are nodes optional? #19

pcraciunoiu opened this issue Jun 4, 2019 · 3 comments

Comments

@pcraciunoiu
Copy link

pcraciunoiu commented Jun 4, 2019

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.

@markedwards
Copy link
Contributor

@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

@pcraciunoiu
Copy link
Author

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

@markedwards
Copy link
Contributor

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 :-)

@pcraciunoiu pcraciunoiu changed the title Why are edges and nodes optional? Why are nodes optional? May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants