nitrogql logonitrogql

nitrogql 1.5 release: We know you better now, fragments

Published at December 13, 2023

Today, we are happy to announce release of nitrogql 1.5!

nitrogql is a toolchain for using GraphQL in TypeScript projects. In 1.5, we added a new option fragmentTypeSuffix to the nitrogql CLI. This option allows you to customize the suffix of the name of the type that is generated for each fragment.

The fragmentTypeSuffix option

Prior to 1.5, nitrogql did not allow you to customize the name of the types generated for fragments. The name of the type was always the same as the name of the fragment. For example:

fragment PartialUser on User {
  name
  email
  iconUrl
}

The type generated for the above fragment was always PartialUser. In 1.5, you can customize the suffix of the type name by using the fragmentTypeSuffix option. An example configuration is:


generate:
  name:
    fragmentTypeSuffix: Fragment
    # ...

With the above configuration, the type generated for the fragment above will be PartialUserFragment.

Why is this useful?

Having a meaningful suffix for a specific kind of types is generally useful. As such, we've already had similar options for other kinds of types and variables. Lack of such an option for fragments was our oversight.

As you might remember, we added support for importing fragments from other GraphQL documents in the previous release. It was the beginning of the process of enlightening ourselves about Fragments and their use cases. This release comes as another step towards that goal.

In addition, the ability to customize the suffix of the type name has been necessary for migrating from other tools that have different naming conventions. Whilst migration is not an easy task, we want to make it as easy as possible.

Conclusion

nitrogql 1.5 is a small release that adds a new option to the nitrogql CLI. The change was contributed by tomocrafter and we thank him for his contribution!


nitrogql is developed by uhyo. Contribution is more than welcome!