All Projects → gajus → Format Graphql

gajus / Format Graphql

Licence: other
Formats GraphQL schema definition language (SDL) document.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Format Graphql

unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 119 (+116.36%)
Mutual labels:  formatter, linter
Railt
⚡️ A PHP GraphQL Framework
Stars: ✭ 353 (+541.82%)
Mutual labels:  graphql, sdl
Graphql To Mongodb
Allows for generic run-time generation of filter types for existing graphql types and parsing client requests to mongodb find queries
Stars: ✭ 261 (+374.55%)
Mutual labels:  graphql, sort
li18nt
🌎 Lint your i18n translation files. Detect conflicting properties, duplicates and make it more readable and easier to maintain by formatting it!
Stars: ✭ 29 (-47.27%)
Mutual labels:  formatter, linter
Graphql Schema Linter
Validate GraphQL schema definitions against a set of rules
Stars: ✭ 476 (+765.45%)
Mutual labels:  graphql, linter
lancer
Turn your python code into a hideous mess. Ever heard of Black? This is the opposite.
Stars: ✭ 179 (+225.45%)
Mutual labels:  formatter, linter
Gts
☂️ TypeScript style guide, formatter, and linter.
Stars: ✭ 3,714 (+6652.73%)
Mutual labels:  linter, formatter
Graphql Go Tools
Tools to write high performance GraphQL applications using Go/Golang.
Stars: ✭ 96 (+74.55%)
Mutual labels:  graphql, linter
Verible
Verible is a suite of SystemVerilog developer tools, including a parser, style-linter, and formatter.
Stars: ✭ 384 (+598.18%)
Mutual labels:  linter, formatter
Isort
A Python utility / library to sort imports.
Stars: ✭ 4,377 (+7858.18%)
Mutual labels:  linter, formatter
Golite
Add essential language support for the Go language to Sublime Text 3.
Stars: ✭ 14 (-74.55%)
Mutual labels:  formatter, linter
Tartiflette
GraphQL Engine built with Python 3.6+ / asyncio
Stars: ✭ 719 (+1207.27%)
Mutual labels:  graphql, sdl
Graphql Parser
A graphql query language and schema definition language parser and formatter for rust
Stars: ✭ 203 (+269.09%)
Mutual labels:  graphql, formatter
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-69.09%)
Mutual labels:  formatter, linter
Prettier
Prettier is an opinionated code formatter.
Stars: ✭ 41,411 (+75192.73%)
Mutual labels:  graphql, formatter
Graphql For Vscode
GraphQL syntax highlighting, linting, auto-complete, and more!
Stars: ✭ 265 (+381.82%)
Mutual labels:  graphql, linter
Godot Gdscript Toolkit
Independent set of GDScript tools - parser, linter and formatter
Stars: ✭ 214 (+289.09%)
Mutual labels:  linter, formatter
Best Of Python Dev
🏆 A ranked list of awesome python developer tools and libraries. Updated weekly.
Stars: ✭ 243 (+341.82%)
Mutual labels:  linter, formatter
Autoflake
Removes unused imports and unused variables as reported by pyflakes
Stars: ✭ 362 (+558.18%)
Mutual labels:  linter, formatter
Devskim
DevSkim is a set of IDE plugins and rules that provide security "linting" capabilities.
Stars: ✭ 576 (+947.27%)
Mutual labels:  linter, sdl

format-graphql

GitSpo Mentions Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Formats GraphQL schema definition language (SDL) document.


Motivation

As schema grows in size, it becomes desirable to automate schema organisation. The primary function of format-graphql is to sort definitions and fields in an alphabetical order, therefore enabling predictable discovery and grouping of related schema entities.

Behaviour

Alphabetically sorts definitions, fields and arguments.

Example

Input:

type Query {
  bananas: [Banana!]!
  apples: [Apple!]!
}

type Apple {
  name: String!
  id: ID!
}

type Banana {
  name: String!
  id: ID!
}

Output:

type Apple {
  id: ID!
  name: String!
}

type Banana {
  id: ID!
  name: String!
}

type Query {
  apples: [Apple!]!
  bananas: [Banana!]!
}

Usage

Command Line

$ format-graphql --help
Sort GraphQL schema definition language (SDL) document.

Positionals:
  sdl-path  Path to the GraphQL schema definition (SDL) document.       [string]

Options:
  --version           Show version number                              [boolean]
  --help              Show help                                        [boolean]
  --sort-arguments    Sort on arguments                [boolean] [default: true]
  --sort-definitions  Sort on definitions              [boolean] [default: true]
  --sort-fields       Sort on fields                   [boolean] [default: true]
  --write             Overrides contents of the SDL document.
                                                      [boolean] [default: false]

$ # Prints formatted schema.
$ format-graphql ./schema.graphql
$
$ # Overrides target schema.
$ format-graphql --write=true ./schema.graphql

Node API

formatSdl(schema, options)

Returns a formatted GraphQL SDL String.

Parameters

  • schema: string

  • options (optional): object:

    {
      sortDefinitions?: boolean,
      sortFields?: boolean,
      sortArguments?: boolean,
    }
    

Example

import {formatSdl} from 'format-graphql';

formatGraphql('type Foo { bar: String }');

Hooks

I recommend using husky to setup a pre-commit hook that would format the schema, e.g.

"husky": {
  "hooks": {
    "pre-commit": "format-graphql --write true src/schema.graphql"
  }
},

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].