Skip to content

Commit

Permalink
support for jsonb filtering (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbek7 authored May 29, 2023
1 parent 8e8dc8d commit 6af2754
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/buildVariables/buildGetListVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ export const buildGetListVariables: BuildGetListVariables =
? `%${obj[key]}%`
: obj[key],
};
filter = set({}, keyName.split(SPLIT_TOKEN), operator);
break;
case 'jsonb':
try {
const parsedJSONQuery = JSON.parse(obj[key]);
if (parsedJSONQuery) {
operator = {
[operation || '_contains']: parsedJSONQuery
};
}
} catch (ex) {}
break;
default:
if (!operator)
Expand All @@ -119,7 +128,6 @@ export const buildGetListVariables: BuildGetListVariables =
? `%${obj[key]}%`
: obj[key],
};
filter = set({}, keyName.split(SPLIT_TOKEN), operator);
}
} else {
// Else block runs when the field is not found in Graphql schema.
Expand All @@ -131,8 +139,8 @@ export const buildGetListVariables: BuildGetListVariables =
? `%${obj[key]}%`
: obj[key],
};
filter = set({}, keyName.split(SPLIT_TOKEN), operator);
}
filter = set({}, keyName.split(SPLIT_TOKEN), operator);
}
return [...acc, filter];
};
Expand Down

0 comments on commit 6af2754

Please sign in to comment.