mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Implemented Prettier for GraphQL formatting (#4022)
* Implemented Prettier for GraphQL formatting (#3242) * package bump and linting Co-authored-by: Dimitri Mitropoulos <dimitrimitropoulos@gmail.com> Co-authored-by: James Gatz <jamesgatzos@gmail.com>
This commit is contained in:
parent
98916c9613
commit
d237b2c907
@ -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';
|
||||
|
||||
@ -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);
|
||||
|
5
packages/insomnia-app/package-lock.json
generated
5
packages/insomnia-app/package-lock.json
generated
@ -15155,6 +15155,11 @@
|
||||
"integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=",
|
||||
"dev": true
|
||||
},
|
||||
"prettier": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.4.1.tgz",
|
||||
"integrity": "sha512-9fbDAXSBcc6Bs1mZrDYb3XKzDLm4EXXL9sC1LqKP5rZkT6KRr/rf9amVUcODVXgguK/isJz0d0hP72WeaKWsvA=="
|
||||
},
|
||||
"pretty-format": {
|
||||
"version": "26.6.2",
|
||||
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz",
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user