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

Nullable interface lists are not idiomatic #484

Closed
ssttevee opened this issue Dec 31, 2018 · 4 comments
Closed

Nullable interface lists are not idiomatic #484

ssttevee opened this issue Dec 31, 2018 · 4 comments
Labels
v0.8 For release in v0.8

Comments

@ssttevee
Copy link

Returning a list of nullable interface types generates a signature that is not idiomatic and is hard to work with.

Expected Behaviour

type Interface interface {
	IsInterface()
}

type QueryResolver interface {
	List(ctx context.Context) ([]Interface, error)
}

Actual Behavior

type Interface interface {
	IsInterface()
}

type QueryResolver interface {
	List(ctx context.Context) ([]*Interface, error)
}

Minimal graphql.schema and models to reproduce

interface Interface {}

type Query {
    list: [Interface]!
}
@JamWils
Copy link

JamWils commented Jan 16, 2019

You're missing an extra exclamation point.

list: [Interface!]!

This is GraphQL saying I want a type of Interface that is not nullable within an array that is not nullable. The generator will generate the correct code at that point.

@ssttevee
Copy link
Author

You're not wrong, but what I want is a non-nullable array of nullable values of that interface type.

@gavbaa
Copy link

gavbaa commented Jan 16, 2019

Per your example, isn't that exactly what you're getting currently?

List(ctx context.Context) ([]*Interface, error)

The array itself is non-nullable (it's just a slice), of nullable values (*Interface). How would Interface be nullable in your expected behavior?

@vektah
Copy link
Collaborator

vektah commented Jan 16, 2019

The array itself is non-nullable (it's just a slice), of nullable values (*Interface). How would Interface be nullable in your expected behavior?

Both slices and interfaces act like pointers, and can be assigned nil without needing to be pointers.

vektah added a commit that referenced this issue Feb 7, 2019
@vektah vektah closed this as completed Feb 7, 2019
@vektah vektah added the v0.8 For release in v0.8 label Feb 7, 2019
vektah added a commit that referenced this issue Feb 7, 2019
cgxxv pushed a commit to cgxxv/gqlgen that referenced this issue Mar 25, 2022
cgxxv pushed a commit to cgxxv/gqlgen that referenced this issue Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v0.8 For release in v0.8
Projects
None yet
Development

No branches or pull requests

4 participants