Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ekryd/sortgraphql

Maven plugin to sort GraphQL Schemas
https://github.com/ekryd/sortgraphql

formatter graphql graphqls hacktoberfest java maven maven-plugin schema

Last synced: 1 day ago
JSON representation

Maven plugin to sort GraphQL Schemas

Awesome Lists containing this project

README

        

# sortgraphql

[![Build Status](https://circleci.com/gh/Ekryd/sortgraphql.svg?style=svg)](https://app.circleci.com/pipelines/github/Ekryd/sortgraphql)
[![Coverage Status](https://coveralls.io/repos/github/Ekryd/sortgraphql/badge.svg?branch=master)](https://coveralls.io/github/Ekryd/sortgraphql?branch=master)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.ekryd.sortgraphql/sortgraphql-maven-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.ekryd.sortgraphql/sortgraphql-maven-plugin)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Ekryd_sortgraphql&metric=alert_status)](https://sonarcloud.io/dashboard?id=Ekryd_sortgraphql)
[![Licence](https://img.shields.io/github/license/Ekryd/sortgraphql?color=success)](https://github.com/Ekryd/sortgraphql/blob/master/LICENSE.md)

Maven plugin to sort GraphQL Schemas.

## Description ##

The plugin will format and sort GraphQL schemas in a predefined way. The default sort order sections are:

* All Directives first
* The Query type
* The Mutation type
* The Subscription type
* All Scalars
* All Interfaces
* All Unions
* All Input types
* All Types (beside Query, Mutation and Subscription)
* All Enums

Within each section, the entities are sorted alphabetically. There are some parameters to suppress the alphabetical
sorting, please submit a pull request or issue if you need more options.

The plugin should be able to handle custom directives and custom scalars. The plugin should also be able to sort
multiple dependent graphql schema files as long as all entities are only defined in one schema.

## Goals Overview ##

The SortGraphQL Plugin has one goal.

* **mvn sortgraphql:sort** sorts the grapql file/files

## Usage ##

Add the plugin to your pom-file to sort the schema each time you build the project. The plugin will execute by default
in the Maven validate phase. Remember to set the `src/main/resources/` path

```xml


...

com.github.ekryd.sortgraphql
sortgraphql-maven-plugin
@pom.version@

src/main/resources/mySchema.graphqls




sort




...

```

## Parameters ##

| **Parameter** | **Default value** | **Description** | **Example** |
|:-----------------------------|:-------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `` | `true` | Should a backup copy be created for the sorted schema. | `false` |
| `` | `.bak` | Name of the file extension for the backup file. | `.temp` |
| `` | `UTF-8` | Encoding for the files. | `ASCII` |
| `` | `false` | By default, if multiple schema files are specified in schema files, then those schemas will be merged together during validation. This flag specifies that each schema should be validated individually. | `-Dsortgraphql.individualSchemas=true`

`true` |
| `` | `src/main/resources/schema.graphqls` | Location of the schema file. Remember to set the `src/main/resources/` path. | `-Dsortgraphql.schemaFile="src/main/resources/main.graphqls"`

`src/main/resources/main.graphqls` |
| `` | `` | Location of multiple graphql schema file that should be sorted. Overrides parameter schemaFile. The schema files can reference each other, but shared definitions are not allowed. |

<schemaFiles>
<schemaFile>src/main/resources/queries.graphqls</schemaFile>
<schemaFile>src/main/resources/mutations.graphqls</schemaFile>
</schemaFiles>
|
| `` | `false` | Set this to 'true' to bypass SortGraphQL plugin. | `-Dsortgraphql.skip=true`

`true` |
| `` | `false` | Set this to 'true' to skip sorting the arguments for a field in a type. | `true` |
| `` | `false` | Set this to 'true' to skip sorting the types in a union. | `true` |
| `` | `false` | Use hash sign for descriptions, instead of keeping string literals (with quote character). | `true` |
| `` | `false` | Generate the 'schema' definition element at the top of the schema, when generating the sorted schema file. | `true` |

## Download ##
The plugin is hosted i [Maven Central](https://mvnrepository.com/artifact/com.github.ekryd.sortgraphql/sortgraphql-maven-plugin) and will be downloaded automatically if you include it as a plugin in your pom file.

## Version history ##

* 2022-09-20: Released 1.1.0 Differentiate between descriptions and comments when processing files.
* 2022-04-02: Released 1.0.0 Supports schema definitions properly.
* 2021-10-11: Released 0.0.4 Added configuration parameters to validate individual schemas. Input types will also have directives on separate line.
* 2021-06-06: Released 0.0.3 Added configuration parameters to customize sorting.
* 2021-06-01: Released 0.0.2 Fully functional but with limited configuration for sorting. Try it out and tell me what you think