|
1 | | -import { Plugin } from "graphile-build"; |
| 1 | +import { Plugin, Build } from "graphile-build"; |
2 | 2 | import { |
3 | 3 | PgEntityKind, |
4 | 4 | PgEntity, |
|
7 | 7 | import { inspect } from "util"; |
8 | 8 | import { entityIsIdentifiedBy } from "./introspectionHelpers"; |
9 | 9 |
|
10 | | -export type PgSmartTagFilterFunction<T> = (input: T) => boolean; |
| 10 | +export type PgSmartTagFilterFunction<T> = (input: T, build: Build) => boolean; |
11 | 11 |
|
12 | 12 | export type PgSmartTagTags = { |
13 | 13 | [tagName: string]: null | true | string | string[]; |
@@ -57,17 +57,17 @@ function compileRule<T extends PgEntity>( |
57 | 57 | ); |
58 | 58 | } |
59 | 59 |
|
60 | | - const match: PgSmartTagFilterFunction<T> = obj => { |
| 60 | + const match: PgSmartTagFilterFunction<T> = (obj, build) => { |
61 | 61 | if (obj.kind !== kind) { |
62 | 62 | return false; |
63 | 63 | } |
64 | 64 |
|
65 | 65 | if (typeof incomingMatch === "function") { |
66 | 66 | // User supplied a match function; delegate to that: |
67 | | - return incomingMatch(obj); |
| 67 | + return incomingMatch(obj, build); |
68 | 68 | } else if (typeof incomingMatch === "string") { |
69 | 69 | // It's a fully-qualified case-sensitive name of the thing. |
70 | | - return entityIsIdentifiedBy(obj, incomingMatch); |
| 70 | + return entityIsIdentifiedBy(obj, incomingMatch, build); |
71 | 71 | } else { |
72 | 72 | throw new Error( |
73 | 73 | "makePgSmartTagsPlugin rule 'match' is neither a string nor a function" |
@@ -140,7 +140,7 @@ export function makePgSmartTagsPlugin( |
140 | 140 |
|
141 | 141 | let hits = 0; |
142 | 142 | relevantIntrospectionResults.forEach(entity => { |
143 | | - if (!rule.match(entity)) { |
| 143 | + if (!rule.match(entity, build)) { |
144 | 144 | return; |
145 | 145 | } |
146 | 146 | hits++; |
|
0 commit comments