SHARE
TWEET

Untitled

a guest Nov 18th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GraphQL Magic Stuff Dynamic Filter
  2.  
  3. // client/serverSideDatasource.js
  4.  
  5. const query = (request, columns) => {
  6.   return {
  7.     query: gql`
  8.       query GetRows($start: Int, $end: Int, $sortModel: [SortModel], $groups: [RowGroup], $groupKeys: [String]) {
  9.         rows(
  10.             startRow: $start,
  11.             endRow: $end,
  12.             sorting: $sortModel,
  13.             rowGroups: $groups,
  14.             groupKeys: $groupKeys
  15.         ) {
  16.             ${getFields(columns)}
  17.         }
  18.       }
  19.     `,
  20.     variables: {
  21.       start: request.startRow,
  22.       end: request.endRow,
  23.       sortModel: mapSortModel(request),
  24.       groups: mapGroups(request),
  25.       groupKeys: mapGroupKeys(request)
  26.     },
  27.   }
  28. };
  29.  
  30. const getFields = (columnDefs) => {
  31.   return columnDefs.map(colDef => colDef.field).join();
  32. };
  33.  
  34. const mapGroups = (request) => {
  35.   return request.rowGroupCols.map(grp => {
  36.     return { colId: grp.field }
  37.   });
  38. };
  39.  
  40. const mapGroupKeys = (request) => {
  41.   return request.groupKeys.map(key => key.toString());
  42. };
  43.  
  44. const mapSortModel = (request) => {
  45.   return request.sortModel.map(srt => {
  46.     return { colId: srt.colId, sort: srt.sort }
  47.   });
  48. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top