-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the ability to apply request specific base filters to the e…
…lasticsearch request
- Loading branch information
1 parent
a118a53
commit e3aee9b
Showing
19 changed files
with
488 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
id: customisations-add-base-filters | ||
title: Adding base filters | ||
sidebar_label: Adding base filters | ||
slug: /customisations/add-base-filters | ||
--- | ||
|
||
You want to apply search filters based on who or where the request is coming from. With `getBaseFilters`, you can return an array of filters to apply to the elasticsearch request. | ||
|
||
The arguments are the same as the resolvers, where you can access the request context, parent object and args. for more information on resolvers, see [resolvers documentation](https://www.apollographql.com/docs/apollo-server/data/resolvers/) | ||
|
||
In this example we show how you could apply a user's role to the search which comes from the user's JWT auth token. For more information on how to do JWT authentication in apollo, see [apollo authorization documentation](https://www.apollographql.com/docs/apollo-server/security/authentication/) | ||
|
||
```javascript | ||
const { typeDefs, withSearchkitResolvers, context } = SearchkitSchema({ | ||
config: searchkitConfig, | ||
typeName: 'ResultSet', | ||
hitTypeName: 'ResultHit', | ||
getBaseFilters: (parent, parameters, ctx, info) => { | ||
return [ | ||
{ term: { "account": parent.accountId }}, | ||
{ term: { "role": ctx.user.role }} | ||
] | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import QueryManager from '../core/QueryManager' | ||
|
||
interface BaseQuery { | ||
getFilter(queryManager: QueryManager): Record<string, unknown> | ||
getFilter(queryManager: QueryManager): Array<Record<string, unknown>> | ||
} | ||
|
||
export default BaseQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.