Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/backend/src/graphql/resolvers/webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,29 @@ describe('Webhook Events Query', (): void => {
expect(typesWithout).not.toContain('outgoing_payment.funded')
expect(typesWithout).not.toContain('outgoing_payment.cancelled')

// Explicit empty array filter should behave like no filter and still exclude them
const withEmptyIn = await appContainer.apolloClient
.query({
query: gql`
query WebhookEvents($filter: WebhookEventFilter) {
webhookEvents(filter: $filter) {
edges {
node {
id
type
}
}
}
}
`,
variables: { filter: { type: { in: [] } } }
})
.then((q): WebhookEventsConnection => q.data!.webhookEvents)

const typesEmpty = withEmptyIn.edges.map((e) => e.node.type)
expect(typesEmpty).not.toContain('outgoing_payment.funded')
expect(typesEmpty).not.toContain('outgoing_payment.cancelled')

// When explicitly requested via filter, they should appear
const withFilter = await appContainer.apolloClient
.query({
Expand Down
11 changes: 8 additions & 3 deletions packages/backend/src/graphql/resolvers/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ export const getWebhookEvents: QueryResolvers<TenantedApolloContext>['webhookEve
const { filter, sortOrder, tenantId, ...pagination } = args
const order = sortOrder === 'ASC' ? SortOrder.Asc : SortOrder.Desc
const webhookService = await ctx.container.use('webhookService')
const filterOrDefaults = filter ?? {
type: { notIn: DEFAULT_EXCLUDED_TYPES }
}
const noFilter =
!filter ||
(filter?.type?.in &&
Array.isArray(filter.type.in) &&
filter.type.in.length === 0)
const filterOrDefaults = noFilter
? { type: { notIn: DEFAULT_EXCLUDED_TYPES } }
: filter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think noFilter would be true if we pass in in: [] but notIn: ['something'] though, right? Meaning we would end up ignoring the notIn filter.

We can either

  • Remove the notIn filter from the schema (but still have it functional in the service method)
  • Do const filter = { type: { notIn: DEFAULT_EXCLUDED_TYPES, in: <parse the in array> } }

const getPageFn = (pagination_: Pagination, sortOrder_?: SortOrder) =>
webhookService.getPage({
pagination: pagination_,
Expand Down
Loading