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:
Ismael Arias 2021-10-01 12:31:02 +02:00 committed by GitHub
parent 98916c9613
commit d237b2c907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -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);

View File

@ -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",

View File

@ -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",