diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/models/backendServiceOption.interface.ts b/aurelia-slickgrid/src/aurelia-slickgrid/models/backendServiceOption.interface.ts index 2107e31e2..f2524d81a 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/models/backendServiceOption.interface.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/models/backendServiceOption.interface.ts @@ -1,4 +1,5 @@ import { BackendEventChanged } from './backendEventChanged.interface'; +import { QueryArgument } from './queryArgument.interface'; export interface BackendServiceOption { /** What is the dataset name, this is required for the GraphQL query to be built */ @@ -16,6 +17,13 @@ export interface BackendServiceOption { /** Execute the process callback command on component init (page load) */ executeProcessCommandOnInit?: boolean; + /** + * Extra query arguments that be passed in addition to the default query arguments + * For example in GraphQL, if we want to pass "userId" and we want the query to look like + * users (first: 20, offset: 10, userId: 123) { ... } + */ + extraQueryArguments?: QueryArgument[]; + /** Backend Service API callback definitions */ onBackendEventApi?: BackendEventChanged; } diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/models/index.ts b/aurelia-slickgrid/src/aurelia-slickgrid/models/index.ts index eed49bfe0..202e60333 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/models/index.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/models/index.ts @@ -62,6 +62,7 @@ export * from './operatorString'; export * from './operatorType.enum'; export * from './pagination.interface'; export * from './paginationChangedArgs.interface'; +export * from './queryArgument.interface'; export * from './searchTerm.type'; export * from './selectOption.interface'; export * from './slickEvent.interface'; diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/models/queryArgument.interface.ts b/aurelia-slickgrid/src/aurelia-slickgrid/models/queryArgument.interface.ts new file mode 100644 index 000000000..8410a6b9d --- /dev/null +++ b/aurelia-slickgrid/src/aurelia-slickgrid/models/queryArgument.interface.ts @@ -0,0 +1,4 @@ +export interface QueryArgument { + field: string; + value: string | number | boolean; +} diff --git a/aurelia-slickgrid/src/aurelia-slickgrid/services/graphql.service.ts b/aurelia-slickgrid/src/aurelia-slickgrid/services/graphql.service.ts index 38f8b582a..38a530445 100644 --- a/aurelia-slickgrid/src/aurelia-slickgrid/services/graphql.service.ts +++ b/aurelia-slickgrid/src/aurelia-slickgrid/services/graphql.service.ts @@ -128,6 +128,12 @@ export class GraphqlService implements BackendService { // first: 20, ... locale: "en-CA" datasetFilters.locale = this.i18n.getLocale() || 'en'; } + if (this.options.extraQueryArguments) { + // first: 20, ... userId: 123 + for (const queryArgument of this.options.extraQueryArguments) { + datasetFilters[queryArgument.field] = queryArgument.value; + } + } // query { users(first: 20, orderBy: [], filterBy: [])} datasetQb.filter(datasetFilters); diff --git a/aurelia-slickgrid/src/examples/slickgrid/example6.ts b/aurelia-slickgrid/src/examples/slickgrid/example6.ts index 5ddf5cb1c..41ef4b1c4 100644 --- a/aurelia-slickgrid/src/examples/slickgrid/example6.ts +++ b/aurelia-slickgrid/src/examples/slickgrid/example6.ts @@ -133,6 +133,10 @@ export class Example6 { datasetName: GRAPHQL_QUERY_DATASET_NAME, isWithCursor: withCursor, addLocaleIntoQuery: true, + extraQueryArguments: [{ + field: 'userId', + value: 123 + }], // when dealing with complex objects, we want to keep our field name with double quotes // example with gender: query { users (orderBy:[{field:"gender",direction:ASC}]) {} diff --git a/client-cli/src/examples/slickgrid/example6.js b/client-cli/src/examples/slickgrid/example6.js index 211308878..7e1b57df0 100644 --- a/client-cli/src/examples/slickgrid/example6.js +++ b/client-cli/src/examples/slickgrid/example6.js @@ -115,6 +115,10 @@ export class Example6 { datasetName: GRAPHQL_QUERY_DATASET_NAME, isWithCursor: withCursor, addLocaleIntoQuery: true, + extraQueryArguments: [{ + field: 'userId', + value: 123 + }], // when dealing with complex objects, we want to keep our field name with double quotes // example with gender: query { users (orderBy:[{field:"gender",direction:ASC}]) {} diff --git a/doc/github-demo/src/examples/slickgrid/example6.ts b/doc/github-demo/src/examples/slickgrid/example6.ts index 80e9799b5..90b962d39 100644 --- a/doc/github-demo/src/examples/slickgrid/example6.ts +++ b/doc/github-demo/src/examples/slickgrid/example6.ts @@ -129,6 +129,10 @@ export class Example6 { datasetName: GRAPHQL_QUERY_DATASET_NAME, isWithCursor: withCursor, addLocaleIntoQuery: true, + extraQueryArguments: [{ + field: 'userId', + value: 123 + }], // when dealing with complex objects, we want to keep our field name with double quotes // example with gender: query { users (orderBy:[{field:"gender",direction:ASC}]) {}