Skip to content

Commit

Permalink
feat(graphql): add option to pass extra query arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Apr 7, 2018
1 parent ba23de3 commit f278c73
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 */
Expand All @@ -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;
}
1 change: 1 addition & 0 deletions aurelia-slickgrid/src/aurelia-slickgrid/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface QueryArgument {
field: string;
value: string | number | boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions aurelia-slickgrid/src/examples/slickgrid/example6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}]) {}
Expand Down
4 changes: 4 additions & 0 deletions client-cli/src/examples/slickgrid/example6.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}]) {}
Expand Down
4 changes: 4 additions & 0 deletions doc/github-demo/src/examples/slickgrid/example6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}]) {}
Expand Down

0 comments on commit f278c73

Please sign in to comment.