Skip to content

Commit

Permalink
Added tabSize setting to prettier format and query results.
Browse files Browse the repository at this point in the history
Closes #741.
  • Loading branch information
imolorhe committed May 13, 2019
1 parent fc80016 commit fb783b3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/app/components/query-result/query-result.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class QueryResultComponent implements OnChanges {
@Input() isSubscribed = false;
@Input() subscriptionResponses = [];
@Input() subscriptionUrl = '';
@Input() tabSize = 2;

@Output() downloadResultChange = new EventEmitter();
@Output() stopSubscriptionChange = new EventEmitter();
Expand All @@ -49,6 +50,8 @@ export class QueryResultComponent implements OnChanges {
resultEditorConfig = {
mode: 'graphql-results',
json: true,
tabSize: this.tabSize,
indentUnit: this.tabSize,
lineWrapping: true,
lineNumbers: true,
foldGutter: true,
Expand Down
1 change: 1 addition & 0 deletions src/app/containers/window/window.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
[isSubscribed]="isSubscribed$ | async"
[subscriptionResponses]="subscriptionResponses$ | async"
[subscriptionUrl]="subscriptionUrl"
[tabSize]="tabSize$ | async"

(downloadResultChange)="downloadResult()"
(stopSubscriptionChange)="stopSubscription()"
Expand Down
6 changes: 3 additions & 3 deletions src/app/effects/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,13 @@ export class QueryEffects {
prettifyQuery$: Observable<queryActions.Action> = this.actions$
.ofType(queryActions.PRETTIFY_QUERY)
.pipe(
withLatestFrom(this.store, (action: queryActions.Action, state) => {
return { data: state.windows[action.windowId], windowId: action.windowId, action };
withLatestFrom(this.store, (action: queryActions.Action, state: fromRoot.State) => {
return { data: state.windows[action.windowId], windowId: action.windowId, action, settings: state.settings };
}),
switchMap(res => {
let prettified = '';
try {
prettified = this.gqlService.prettify(res.data.query.query);
prettified = this.gqlService.prettify(res.data.query.query, res.settings.tabSize);
} catch (err) {
debug.log(err);
this.notifyService.error('Your query does not appear to be valid. Please check it.');
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/gql/gql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ export class GqlService {
* Prettifies (formats) a given query
* @param query
*/
prettify(query: string) {
prettify(query: string, tabWidth: number = 2) {
// return print(parse(query));
return prettier.format(query, { parser: 'graphql', plugins: [ prettierGraphql ] });
return prettier.format(query, { parser: 'graphql', plugins: [ prettierGraphql ], tabWidth });
}

/**
Expand Down

0 comments on commit fb783b3

Please sign in to comment.