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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple order fields through an edge #4009

Open
1 task done
henrywoody opened this issue Apr 10, 2024 · 0 comments
Open
1 task done

Support for multiple order fields through an edge #4009

henrywoody opened this issue Apr 10, 2024 · 0 comments

Comments

@henrywoody
Copy link
Contributor

henrywoody commented Apr 10, 2024

It would be great to have support for multiple order fields through a single edge.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 馃挕

Say you have a schema like this:

// User model

func (User) Fields() []ent.Field {
	return []ent.Field{
		field.String("first_name").
			Annotations(entgql.OrderField("FIRST_NAME")),
		field.String("last_name").
			Annotations(entgql.OrderField("LAST_NAME")),
	}
}

// Book model

func (Book) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("author", User.Type).
			Ref("books"),
	}
}

And you want to be able to order by the author's first name or last name.

Could look like this:

func (Book) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("author", User.Type).
			Ref("books").
			Annotations(
				entgql.OrderFields("AUTHOR_FIRST_NAME", "AUTHOR_LAST_NAME"),
			),
	}
}

Given my (limited) understand of how the templating works I think this API would be the easiest to add, but it could also just be that entgql.OrderField is updated to accept multiple arguments or that you could pass multiple entgql.OrderFields (but that last one seems the most difficult to implement).

Motivation 馃敠

One should not be limited to ordering by only one field when ordering through an edge.

@henrywoody henrywoody changed the title Support for multiple order field annotations on an edge Support for multiple order fields through an edge Apr 10, 2024
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

1 participant