Skip to content

Commit

Permalink
refactor(graphql): GraphqlService should not require any constructor arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghislain Beaulac authored and Ghislain Beaulac committed May 23, 2018
1 parent ee46660 commit eb4e249
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/app/examples/grid-graphql.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ export class GridGraphqlComponent implements OnInit, OnDestroy {
pageSize: defaultPageSize,
totalItems: 0
},

params: {
i18n: this.translate
},
presets: {
// you can also type operator as string, e.g.: operator: 'EQ'
filters: [
Expand All @@ -107,9 +109,8 @@ export class GridGraphqlComponent implements OnInit, OnDestroy {
],
pagination: { pageNumber: 2, pageSize: 20 }
},

backendServiceApi: {
service: new GraphqlService(this.translate),
service: new GraphqlService(),
options: this.getBackendOptions(this.isWithCursor),
// you can define the onInit callback OR enable the "executeProcessCommandOnInit" flag in the service init
// onInit: (query) => this.getCustomerApiCall(query)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { mapOperatorType, mapOperatorByFilterType, mapOperatorByFieldType } from './utilities';
import {
BackendService,
Expand Down Expand Up @@ -33,7 +32,6 @@ const DEFAULT_FILTER_TYPING_DEBOUNCE = 750;
const DEFAULT_ITEMS_PER_PAGE = 25;
const DEFAULT_PAGE_SIZE = 20;

@Injectable()
export class GraphqlService implements BackendService {
private _currentFilters: ColumnFilters | CurrentFilter[];
private _currentPagination: CurrentPagination;
Expand All @@ -48,8 +46,6 @@ export class GraphqlService implements BackendService {
offset: 0
};

constructor(private translate: TranslateService) {}

/** Getter for the Grid Options pulled through the Grid Object */
private get _gridOptions(): GridOption {
return (this._grid && this._grid.getOptions) ? this._grid.getOptions() : {};
Expand Down Expand Up @@ -128,7 +124,7 @@ export class GraphqlService implements BackendService {
}
if (this.options.addLocaleIntoQuery) {
// first: 20, ... locale: "en-CA"
datasetFilters.locale = this.translate.currentLang || 'en';
datasetFilters.locale = (this._gridOptions.params && this._gridOptions.params.i18n && this._gridOptions.params.i18n.currentLang) || 'en';
}
if (this.options.extraQueryArguments) {
// first: 20, ... userId: 123
Expand Down

0 comments on commit eb4e249

Please sign in to comment.