GraphQLize Update (#2) - Supports Sorting, Filtering & MySQL Boolean Types

Author, GraphQLize

Hello World,

GraphQLize is one month old now ๐ŸŽ‚, and it is getting better day by day. Almost 50% of the planned features are complete ๐Ÿ™Œ.

As usual in this blog post, I am going to share what's new in GraphQLize and what is in the pipeline for the next two weeks.

Here we go!

Sorting

GraphQLize now enables sorting the query results using the orderBy argument. By default, you can use any of the table columns to sort the query results. In future, we can control this behaviour.

query languagesSortedByName {
# sorts using the `name` column in the `language` table
languages(orderBy: {name: ASC}) {
name
}
}

If you'd like to sort it in descending order, replace ASC with DESC.

query languagesSortedByNameInDescOrder {
languages(orderBy: {name: DESC}) {
name
}
}

We can sort by multiple columns as well,

query {
# sorts the `actor` table by the `first_name` column
# and then by `last_name` column in descending order
actors(orderBy: {firstName: ASC, lastName: DESC}) {
firstName
lastName
}
}

GraphQLize also supports sorting nested objects.

query {
countryByCountryId(countryId: 2) {
country
# sorting one-to-many relationship
cities(orderBy: {city: DESC}) {
city
}
}
}
query {
actorByActorId(actorId: 148) {
firstName
# sorting many-to-many relationship
films(orderBy: {title: DESC}) {
title
}
}
}
note

Currently, sorting nested objects in MySQL is not supported. in a later release.

Filtering

Filtering is another critical feature that was released in the last iteration. Like orderBy in sorting, we have the where argument using which we can specify the filter condition.

Here are some of the examples of using eq, in, isNull and between filter conditions.

query {
cities(where: {cityId: {eq: 3}}) {
city
}
}
query {
payments(where: {customerId: {in: [1, 2]}}) {
paymentId
amount
}
}
query {
employees(where: {employeeReportsToId: {isNull: true}}) {
firstName
lastName
}
}
query {
payments(where: {paymentDate: {between: {from: "2005-08-23T21:00:00", to: "2005-08-23T21:03:00"}}}) {
rentalId
}
}

For the detailed set of supported filter conditions, you can check out this documentation.

We can filter the nested objects also.

query {
countryByCountryId(countryId: 2) {
country
# filter one-to-many relationship
cities(where: {city: {like: "B%"}}) {
cityId
city
}
}
}
query {
actorByActorId(actorId: 148) {
firstName
# filter many-to-many relationship
films(where: {title: {like: "S%"}}) {
title
}
}
}

MySQL Boolean Data Type Support

The last feature that was developed as part of the previous iteration is the support for MySQL boolean data type.

GraphQLize treats the column types BIT(1) and TINYINT(1) as the Boolean GraphQL scalar type.

Here is an example of using it in a filter condition to filter only active customers.

query {
customers(where: {active: {eq: true}}) {
firstName
}
}

What's Next?

I am planning to take a short break for two days to sustain my progress and energy level. Then, I am going to work on the following issues for the next two weeks.

  • Supporting , and operators in the filter conditions.

  • Ability to filter based on the nested object's fields -

  • Filter based on the existence of nested objects -

I am keeping this iteration light as I may not be able to spend some good quality time outside my work hours. In case, if I am free, I would take some more features around filtering. Let's see how it goes ๐Ÿคž.

You can keep track of the progress by

  • Following the
  • Joining
  • Subscribing to

โญ๏ธ If you like GraphQLize, give it a star on ! โญ๏ธ

That's all!

Cheers,
Tamizh