Skip to content

Commit

Permalink
Implemented Prettier for GraphQL formatting (#4022)
Browse files Browse the repository at this point in the history
* Implemented Prettier for GraphQL formatting (#3242)

* package bump and linting

Co-authored-by: Dimitri Mitropoulos <[email protected]>
Co-authored-by: James Gatz <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2021
1 parent 98916c9 commit d237b2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { ModifiedGraphQLJumpOptions } from 'codemirror-graphql/jump';
import electron, { OpenDialogOptions } from 'electron';
import { readFileSync } from 'fs';
import { DefinitionNode, DocumentNode, GraphQLNonNull, GraphQLSchema, NonNullTypeNode, OperationDefinitionNode } from 'graphql';
import { parse, print, typeFromAST } from 'graphql';
import { parse, typeFromAST } from 'graphql';
import Maybe from 'graphql/tsutils/Maybe';
import { buildClientSchema, getIntrospectionQuery } from 'graphql/utilities';
import { json as jsonPrettify } from 'insomnia-prettify';
import prettier from 'prettier';
import React, { PureComponent } from 'react';
import ReactDOM from 'react-dom';

Expand Down Expand Up @@ -459,7 +460,11 @@ export class GraphQLEditor extends PureComponent<Props, State> {
_handlePrettify() {
const { body } = this.state;
const { variables, query } = body;
const prettyQuery = query && print(parse(query));
const prettyQuery = prettier.format(query, {
parser: 'graphql',
useTabs: this.props.settings.editorIndentWithTabs,
tabWidth: this.props.settings.editorIndentSize,
});
const prettyVariables = variables && JSON.parse(jsonPrettify(JSON.stringify(variables)));

this._handleBodyChange(prettyQuery, prettyVariables, this.state.body.operationName);
Expand Down
5 changes: 5 additions & 0 deletions packages/insomnia-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/insomnia-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"openapi-2-kong": "2.3.2",
"papaparse": "^5.2.0",
"pdfjs-dist": "^2.5.207",
"prettier": "2.4.1",
"ramda": "^0.27.1",
"ramda-adjunct": "^2.33.0",
"react": "^16.8.3",
Expand Down

0 comments on commit d237b2c

Please sign in to comment.