Configuration

Options name in this documentation are in camel case. If you're using Pretty GraphQL as a Rust crate, please use snake case instead.

printWidth

The line width limitation that Pretty GraphQL should (but not must) avoid exceeding. Pretty GraphQL will try its best to keep line width less than this value, but it may exceed for some cases, for example, a very very long single word.

Default option is 80.

Example for 80

query Query($veryVeryVeryVeryLong: VeryVeryVeryVeryLong) {
  field
}

Example for 40

query Query(
  $veryVeryVeryVeryLong: VeryVeryVeryVeryLong
) {
  field
}

useTabs

Specify use space or tab for indentation.

Default option is false.

indentWidth

Size of indentation. When enabled useTabs, this option may be disregarded, since only one tab will be inserted when indented once.

Default option is 2. This can't be zero.

Examples below will are based on useTabs: false.

Example for 2

{
  field
}

Example for 4

{
    field
}

lineBreak

Specify use \n (LF) or \r\n (CRLF) for line break.

Default option is "lf". Possible options are "lf" and "crlf".

comma

Control whether commas should be inserted inside a list of items.

Possible option values:

  • "always": Insert commas inside a list of items. For single line list, there won't be trailing comma; for multiple lines list, there will be trailing comma.
  • "never": Do not insert commas inside a list of items. All existed commas will be removed.
  • "noTrailing": Insert commas inside a list of items without trailing comma.
  • "onlySingleLine": Insert commas inside a list of items only for single line list. For multiple lines list, there won't be commas.
  • "inherit": Inherit from the base comma option.

Default option value is "onlySingleLine".

This global option can be overridden by different syntax nodes. Some syntax-node-specific options will override by default instead of "inherit":

  • arguments.comma
  • argumentsDefinition.comma
  • directives.comma (default: "never")
  • enumValuesDefinition.comma (default: "never")
  • fieldsDefinition.comma (default: "never")
  • inputFieldsDefinition.comma (default: "never")
  • listValue.comma
  • objectValue.comma
  • schemaDefinition.comma (default: "never")
  • schemaExtension.comma (default: "never")
  • selectionSet.comma (default: "never")
  • variableDefinitions.comma

Example for "always"

Single line:

query Query($a: A, $b: B)  {
  field1
  field2
}

Multiple lines:

query Query(
  $a: A,
  $b: B,
)  {
  field1
  field2
}

Example for "never"

Single line:

query Query($a: A $b: B)  {
  field1
  field2
}

Multiple lines:

query Query(
  $a: A
  $b: B
)  {
  field1
  field2
}

Example for "noTrailing"

Single line:

query Query($a: A, $b: B)  {
  field1
  field2
}

Multiple lines:

query Query(
  $a: A,
  $b: B
)  {
  field1
  field2
}

Example for "onlySingleLine"

Single line:

query Query($a: A, $b: B)  {
  field1
  field2
}

Multiple lines:

query Query(
  $a: A
  $b: B
)  {
  field1
  field2
}

singleLine

Control whether items should be placed on single line as possible, even they're originally on multiple lines, or force them to be on multiple lines.

Possible option values:

  • "prefer": Place items on single line as possible.
  • "smart": Whether items should be placed on single line will be determined by original layout.
  • "never": Force items to be on multiple lines.
  • "inherit": Inherit from the base singleLine option.

Default option value is "smart".

This global option can be overridden by different syntax nodes. Some syntax-node-specific options will override by default instead of "inherit":

  • arguments.singleLine
  • argumentsDefinition.singleLine
  • directiveLocations.singleLine
  • directives.singleLine
  • enumValuesDefinition.singleLine (default: "never")
  • fieldsDefinition.singleLine (default: "never")
  • implementsInterfaces.singleLine
  • inputFieldsDefinition.singleLine (default: "never")
  • listValue.singleLine
  • objectValue.singleLine
  • schemaDefinition.singleLine (default: "never")
  • schemaExtension.singleLine (default: "never")
  • selectionSet.singleLine (default: "never")
  • unionMemberTypes.singleLine
  • variableDefinitions.singleLine

Example for "prefer"

query Query(
  $a: A
  $b: B
) {
  field1
  field2
}

will be formatted as:

query Query($a: A, $b: B) {
  field1
  field2
}

Example for "smart"

query Query(
  $a: A
  $b: B
) {
  field1
  field2
}

will be formatted as:

query Query(
  $a: A
  $b: B
) {
  field1
  field2
}

which is the same as the original layout.

But,

query Query($a: A
  $b: B
) {
  field1
  field2
}

will be formatted as:

query Query($a: A, $b: B) {
  field1
  field2
}

Example for "never"

query Query($a: A, $b: B) {
  field1
  field2
}

will be formatted as:

query Query(
  $a: A
  $b: B
) {
  field1
  field2
}

parenSpacing

Control whether whitespace should be inserted between parentheses or not.

Default option is false.

This global option can be overridden by different syntax nodes:

  • arguments.parenSpacing
  • argumentsDefinition.parenSpacing
  • variableDefinitions.parenSpacing

Example for false

query Query($a: A) @directive(key: "value") {
  field
}

Example for true

query Query( $a: A ) @directive( key: "value" ) {
  field
}

bracketSpacing

Control whether whitespace should be inserted between brackets or not.

Default option is false.

Currently this option is only applied for listValue syntax node, so there're no syntax-node-specific options.

Example for false

query Query @directive(key: [1, 2, 3]) {
  field
}

Example for true

query Query @directive(key: [ 1, 2, 3 ]) {
  field
}

braceSpacing

Control whether whitespace should be inserted between braces or not.

Default option is true.

This global option can be overridden by different syntax nodes:

  • enumValuesDefinition.braceSpacing
  • fieldsDefinition.braceSpacing
  • inputFieldsDefinition.braceSpacing
  • objectValue.braceSpacing
  • schemaDefinition.braceSpacing
  • schemaExtension.braceSpacing
  • selectionSet.braceSpacing

Example for false

query Query($object: Any = {key: "value"}) {
  field
}

Example for true

query Query($object: Any = { key: "value" }) {
  field
}

formatComments

Control whether whitespace should be inserted at the beginning of comments or not.

When this option is set to false, comments contain leading whitespace will still be kept as-is.

Default option is false.

Example for true

#comment

will be formatted as:

# comment

ignoreCommentDirective

Text directive for ignoring formatting specific statement.

Default is "pretty-graphql-ignore", but if you're using as a plugin in dprint, it will be "dprint-ignore".

Example

{
  # pretty-graphql-ignore
  hero {
       name
    height
  }
}