package
Formats GraphQL schema definition language (SDL) document.
npm install format-graphqlGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 12 packages.
6.9 MB
Includes dependencies.
Formats GraphQL schema definition language (SDL) document.
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.
Alphabetically sorts definitions, fields and arguments.
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!]!
}
$ 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-enums Sort on enums [boolean] [default: true]
--sort-fields Sort on fields [boolean] [default: true]
formatSdl(schema, options)
Returns a formatted GraphQL SDL String.
schema: string
options (optional): object:
{
sortDefinitions?: boolean,
sortEnums?: boolean,
sortFields?: boolean,
sortArguments?: boolean,
}import {formatSdl} from 'format-graphql';
formatGraphql('type Foo { bar: String }');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"
}
},