@authentified/retool-scripts
v0.14.0
Published
A collection of Retool scripts designed to make integrating with [Gadget's APIs](https://gadget.dev/) a lot easier.
Downloads
391
Readme
@authentified/retool-scripts
A collection of Retool scripts designed to make integrating with Gadget's APIs a lot easier.
Installation
Add the Authentified Retool scripts Unpkg URL to your Retool libraries.
https://unpkg.com/@authentified/retool-scripts
If needed, you can also include via various package managers:
npm install @authentified/retool-scripts
yarn add @authentified/retool-scripts
pnpm add @authentified/retool-scripts
Functions
transformFilterStackToGraphQLFilter
This function translates a Retool table filter stack to Gadget's GraphQL Filters. Create a transformer also called transformFilterStackToGraphQLFilter
and paste the following code.
return window.Authentified.transformFilterStackToGraphQLFilter(
{{ myTable.filterStack }}
)
This Transformer can now be used to generate the filter
argument for your GraphQL query.
You can also append an extra GraphQL filter as a second argument if you want to ensure particular filters are passed to a query. If the filter stack is empty, the extra
parameter will be used as the default filter:
return window.Authentified.transformFilterStackToGraphQLFilter(
{{ myTable.filterStack }},
{ status: { equals: "published" }}
)
Filtering on related models
To enable filtering on related models, you will need to change the ID of the column to a dot notation representation of the filter. For example if you have a reference to a model named product
, and you want to search by a field called title
you just change the ID of your column to product.title
and transformFilterStackToGraphQLFilter will do the rest.
transformSortArrayToGraphQLSortOrder
This function translates a Retool sort array to Gadget's GraphQL SortOrder. Create a transformer also called transformSortArrayToGraphQLSortOrder
and paste the following code.
return window.Authentified.transformSortArrayToGraphQLSortOrder(
{{ listingsTable.sortArray }}
)
You can also prepend an additional SortBy object it you want to ensure a particular default SortBy is passed to a query:
return window.Authentified.transformSortArrayToGraphQLSortOrder(
{{ listingsTable.sortArray }},
{ createdAt: "Descending" },
)