BehaviorBehavior(行为控制)
For all but the simplest APIs you will want to control which parts of your data sources are exposed and how they are exposed. New to PostGraphile version 5 is the “behavior” system that gives you granular control over these topics.
除了最简单的 API 之外,实际项目中通常都需要控制数据源的哪些部分可以对外暴露,以及以何种方式暴露。PostGraphile V5 全新引入的“behavior(行为)”系统,正是为此提供精细化的控制能力。
Terminology基本概念
A “behavior string” is a text-based string with a relatively simple syntax; here are some examples:
“behavior 字符串(behavior string)”是一种语法简洁的纯文本配置串,示例如下:
insert+list -connection -list:filter-insert -update -delete query:*:filter +connection -list
A behavior string is made of a list of “behavior fragments” separated by spaces.
Each behavior fragment optionally starts with a + or - symbol (if neither is
specified then + is inferred) followed by a “scope string.” A scope string is
one or more “scope phrases” joined by colons (:). A scope phrase is either a
simple alphanumeric word (in camelCase), or an asterisk (*).
一个 behavior 字符串由若干以空格分隔的“behavior 片段(behavior fragment)”组成。每个 behavior 片段可选地以 + 或 - 开头(若省略前缀,则默认为 +),其后紧跟一个“作用域字符串(scope string)”。作用域字符串是由一个或多个“作用域短语(scope phrase)”通过冒号(:)拼接而成的。每个作用域短语既可以是简单的驼峰命名(camelCase)字母数字单词,也可以是通配符星号(*)。
Determining entity behavior确定实体的 behavior
Many entities that PostGraphile processes when generating a schema (for example:
tables, columns, functions, types, etc.) have associated behaviors which
influence whether and how that entity is exposed. You may influence their
resulting behaviors by adding your own behavior strings to the entity, either
directly or via smart tags/smart comments. For example, if you don’t want users
to be able to modify entries in the forums table, you might add a database
comment such as comment on table forums is '@behavior -insert -update -delete'; (this is just one of many ways of attaching behaviors).
在生成 schema 的过程中,PostGraphile 处理的许多实体(如表、列、函数、类型等)都关联了各自的 behavior,用以决定该实体是否暴露以及如何暴露。你可以直接为实体附加自定义 behavior 字符串,或通过 smart tag / smart comment 来调整最终生效的 behavior。例如,若不希望用户修改 forums 表中的记录,可以添加如下数据库注释:comment on table forums is '@behavior -insert -update -delete';(这只是众多附加 behavior 的方式之一)。
The final behavior string of an entity is made by concatenating the behavior strings from various sources; typically this follows the following pattern:
实体最终的 behavior 字符串由来自不同来源的多段 behavior 字符串依次拼接而成,通常遵循以下顺序:
-
Default behaviors from plugins
插件提供的默认 behavior
-
Global default behavior
全局默认 behavior
-
Inferred behaviors from plugins
插件自动推断的 behavior
-
(Secondary entity behaviors)
(次级实体的 behavior)
-
E.g. if the entity is a column, then secondary entity behaviors may include the behavior of the data type of the column (codec)
例如,若当前实体是一个列,次级实体的 behavior 可能包含该列数据类型(codec)的 behavior
-
-
Entity behavior (from smart tags/smart comments)
实体自身的 behavior(来自 smart tag / smart comment)
The highest precedence behaviors are at the end the behavior string, and the lowest priority behaviors are at the start.
在整个 behavior 字符串中,越靠后的片段优先级越高,越靠前的片段优先级越低。
When determining if an entity possesses a given “filter” behavior, the system
will scan backwards through the entity’s behavior string for the first fragment
that matches the filter; if the matching fragment has a - modifier then the
entity does not possess that behavior (even if a positive fragment existed
earlier in the behavior string) otherwise it does.
当系统判断某个实体是否具备指定“过滤目标(filter)”的 behavior 时,会从后往前反向扫描该实体的 behavior 字符串,查找第一个与该过滤目标匹配的片段:如果匹配到的片段带有 - 修饰符,则判定该实体不具备此 behavior(即便字符串靠前位置曾出现过正向片段亦然);否则即判定为具备。
Use npx graphile behavior debug to inspect how behaviors are derived for
specific entities. It is a quick way to confirm which fragments are winning and
why.
可以使用 npx graphile behavior debug 命令查看特定实体的 behavior 推导过程,这是确认究竟是哪条片段最终生效及其原因的快捷方法。
Global default behavior全局默认 behavior
If you want to make wide-sweeping changes to behaviors, you can add “default
behaviors” via the preset.schema.defaultBehavior setting. For example if you
want your schema to use lists by default, eschewing the more verbose (but
typically superior) connections pattern, you might have a configuration
something like this:
如果你想对 behavior 进行大范围的全局调整,可以通过 preset.schema.defaultBehavior 设置“默认 behavior”。例如,如果你希望 schema 默认采用列表形式,而舍弃虽然通常更优但偏冗长的 Connection 形式,可以像下面这样配置:
// graphile.config.mjs
const preset = {
//...
schema: {
//...
defaultBehavior: "-connection +list",
},
};
export default preset;
These global defaults can still be overridden by each entity, so they’re a good way of making wide ranging “default” behaviors without locking yourself in too hard.
这些全局默认值仍可在单个实体级别被覆盖,因此既能大范围统一修改默认 behavior,又不会把配置彻底写死。
If you’re authoring a preset that is not the final configuration for a schema
then this default behavior setting is likely to be overridden (replaced) by the
user’s configuration. Instead, preset authors should add a plugin that has a
schema.globalBehavior entry. If this entry is a string, the behavior will be
prepended. If it’s a callback, then it should return an array of behavior
strings to be joined, one of which should be the current (passed in) behavior.
Typically you want a tuple where the first entry is your new behaviors and the
second entry is the current (passed-in) behavior (this way the user’s
defaultBehavior will have higher precedence to your globalBehavior).
如果你正在编写一个供他人复用的 preset(而非最终应用的完整 schema 配置),直接使用 defaultBehavior 很可能会被用户的自定义配置整体覆盖(替换)。对于 preset 作者,更推荐在插件中声明 schema.globalBehavior 配置项:如果该配置项是字符串,其内容会被拼接到现有 behavior 的最前面;如果它是一个回调函数,则应返回一个待拼接的 behavior 字符串数组,且其中需包含传入的当前 behavior。通常建议返回一个二元组,第一项为你要注入的新 behavior,第二项为传入的当前 behavior——这样一来,用户自己配置的 defaultBehavior 就能拥有比 globalBehavior 更高的优先级。
A similar “lists by default” plugin might look like this:
一个同样实现“默认使用列表”的插件写法如下:
const FavourListsPlugin = {
name: "FavourListsPlugin",
version: "0.0.0",
schema: {
globalBehavior: "-connection +list",
},
};
or, equivalently, like this:
或者等价地写成这样:
const FavourListsPlugin = {
name: "FavourListsPlugin",
version: "0.0.0",
schema: {
globalBehavior(currentBehavior, resolvedPreset) {
return ["-connection +list", currentBehavior];
},
},
};
Core behaviors核心 behavior 列表
TODO: We really need an automated registry of this, and to validate plugins against it. But for now, this list will have to suffice.
TODO:后续我们非常需要为此建立一份自动化的 registry 并据此校验插件,但在那之前,请暂且参考以下清单。
Scopes are least specific on the right (broad operations like select or
update) and narrow more as prefixes are added to the left (resource:update
is narrower than update; constraint:resource:update is narrower still).
作用域越靠右越宽泛(如 select 或 update 这类通用操作),随着左侧不断添加前缀而逐步收窄(resource:update 比 update 更具体,而 constraint:resource:update 则进一步收窄)。
The following are behaviors that the core PostGraphile/graphile-build/graphile-build-pg plugins utilize:
以下是核心插件 PostGraphile / graphile-build / graphile-build-pg 所使用的 behavior:
-
select- can select this resource/column/etc. Note this does not necessarily mean you can doselect * from usersbut it might mean that it’s possible to see details about auserswhen it’s returned by a function or similar. (In this case thecodechasselectbut theresourcehas-select.)select- 允许查询(select)该 resource / 列等。注意这并不一定意味着你可以执行select * from users,而可能仅表示当函数等返回users时,能够读取其中的字段详情。(此时对应的codec拥有select,而resource则带有-select。) -
resource:select- can select rows from this resourceresource:select- 允许从该 resource 中查询数据行 -
insert:resource:select- can select the row that was inserted (on the mutation payload)insert:resource:select- 允许在 mutation payload 中查询刚刚插入的数据行 -
update:resource:select- can select the row that was updated (on the mutation payload)update:resource:select- 允许在 mutation payload 中查询刚刚更新的数据行 -
delete:resource:select- can select the row that was deleted (on the mutation payload)delete:resource:select- 允许在 mutation payload 中查询刚刚删除的数据行 -
delete:resource:nodeId- can select the nodeId of the row that was deleted (on the mutation payload)delete:resource:nodeId- 允许在 mutation payload 中查询已删除数据行的 nodeId -
resource:insert- can insert into this resourceresource:insert- 允许向该 resource 插入数据 -
resource:update- can update a record in this resourceresource:update- 允许更新该 resource 中的记录 -
resource:delete- can delete a record in this resourceresource:delete- 允许删除该 resource 中的记录 -
resource:list- “list” field for a resource at any levelresource:list- 在任意层级为该 resource 生成“列表(list)”字段 -
resource:connection- “connection” field for a resource at any levelresource:connection- 在任意层级为该 resource 生成“Connection”字段 -
resource:list:filter- can we filter this resource’s results (when represented as a list)?resource:list:filter- 当该 resource 以列表形式返回时,是否支持对其结果进行过滤 -
resource:list:order- can we order this resource’s results (when represented as a list)?resource:list:order- 当该 resource 以列表形式返回时,是否支持对其结果进行排序 -
resource:connection:filter- can we filter this resource’s results (when represented as a connection)?resource:connection:filter- 当该 resource 以 Connection 形式返回时,是否支持对其结果进行过滤 -
resource:connection:order- can we order this resource’s results (when represented as a connection)?resource:connection:order- 当该 resource 以 Connection 形式返回时,是否支持对其结果进行排序 -
resource:connection:backwards- can we paginate backwards through this resource’s results (when represented as a connection)?resource:connection:backwards- 当该 resource 以 Connection 形式返回时,是否支持反向分页查询 -
resource:aggregates- does this resource support aggregates across its attributes (i.e. does theaggregatesfield get added to connections)resource:aggregates- 该 resource 是否支持对其属性进行聚合计算(即是否在 Connection 上添加aggregates字段) -
resource:groupedAggregates- does this resource support grouped aggregates across its attributes (i.e. does thegroupedAggregatesfield get added to connections)resource:groupedAggregates- 该 resource 是否支持对其属性进行分组聚合计算(即是否在 Connection 上添加groupedAggregates字段) -
resource:groupedAggregates:having- can groupedAggregates on this resource have a ‘having’ clause?resource:groupedAggregates:having- 该 resource 的分组聚合(groupedAggregates)是否支持 ‘having’ 子句 -
sum:resource:groupedAggregates:having- can groupedAggregates on this resource have a ‘having’ clause that uses the ‘sum’ aggregate?sum:resource:groupedAggregates:having- 该 resource 的分组聚合(groupedAggregates)是否允许在 ‘having’ 子句中使用 ‘sum’ 聚合 -
sum:resource:aggregates- does this resource support ‘sum’ aggregates across its attributes (replace ‘sum’ with the aggregate id you care about) (i.e. does thesumfield get added within theaggregatesfield on connections?)sum:resource:aggregates- 该 resource 是否支持对其属性执行 ‘sum’ 聚合(可将 ‘sum’ 替换为其他所需的聚合 ID;即是否在 Connection 的aggregates字段下添加sum字段) -
constraint:resource:update- can update a record by this constraintconstraint:resource:update- 允许根据该约束更新记录 -
constraint:resource:delete- can delete a record by this constraintconstraint:resource:delete- 允许根据该约束删除记录 -
nodeId:resource:update- can update a record by its NodeIDnodeId:resource:update- 允许根据 Node ID 更新记录 -
nodeId:resource:delete- can delete a record by its NodeIDnodeId:resource:delete- 允许根据 Node ID 删除记录 -
attribute:select- can this attribute be selected?attribute:select- 是否允许查询该属性(attribute) -
attribute:insert- can this attribute be inserted into?attribute:insert- 是否允许向该属性插入值 -
attribute:update- can this attribute be updated?attribute:update- 是否允许更新该属性 -
attribute:base- should we add this attribute to the “base” input type?attribute:base- 是否将该属性添加到“基础(base)”input 类型中 -
attribute:aggregate- can we aggregate on this attribute?attribute:aggregate- 是否允许对该属性进行聚合计算 -
sum:attribute:aggregate- can we perform the ‘sum’ aggregate on this attribute? (replace ‘sum’ with the aggregate id you care about) (i.e. does this attribute get added to thesumfield on theaggregatesfield on connections?)sum:attribute:aggregate- 是否允许对该属性执行 ‘sum’ 聚合(可将 ‘sum’ 替换为其他聚合 ID;即是否将该属性添加到 Connection 上aggregates字段下的sum字段中) -
sum:resource:aggregate- does this computed-column-like resource support the ‘sum’ aggregate when acting as an attribute (replace ‘sum’ with the aggregate id you care about)sum:resource:aggregate- 当类似计算列的 resource 作为属性使用时,是否支持 ‘sum’ 聚合(可将 ‘sum’ 替换为其他聚合 ID) -
attribute:groupBy- can we group by this attribute when performing grouped aggregates?attribute:groupBy- 执行分组聚合时,是否允许按该属性进行分组(groupBy) -
attribute:havingBy- can this attribute be used in the ‘having’ clause of a grouped aggregate?attribute:havingBy- 该属性是否可用于分组聚合的 ‘having’ 子句中 -
sum:attribute:havingBy- can the sum of this attribute be used in the ‘having’ clause of a grouped aggregate?sum:attribute:havingBy- 该属性的求和值(sum)是否可用于分组聚合的 ‘having’ 子句中 -
resource:havingBy- can this computed-column-like resource be used in the ‘having’ clause of a grouped aggregate?resource:havingBy- 该类似计算列的 resource 是否可用于分组聚合的 ‘having’ 子句中 -
sum:resource:havingBy- can the sum of this computed-column-like resource be be used in the ‘having’ clause of a grouped aggregate?sum:resource:havingBy- 该类似计算列的 resource 的求和值(sum)是否可用于分组聚合的 ‘having’ 子句中 -
nodeId:insert- can we insert to the columns represented by this nodeId which represents a table related via foreign key constraint?nodeId:insert- 插入数据时,是否允许通过该 nodeId(代表经外键约束关联的目标表)来写入对应的外键列 -
nodeId:update- can we update the columns represented by this nodeId which represents a table related via foreign key constraint?nodeId:update- 更新数据时,是否允许通过该 nodeId(代表经外键约束关联的目标表)来修改对应的外键列 -
nodeId:base- should we add a nodeId input representing this foreign key constraint to the “base” input type?nodeId:base- 是否在“基础(base)”input 类型中添加一个代表此外键约束的 nodeId input 字段 -
type:node- should the GraphQLObjectType (type) this codec represents implement the GraphQL Global Object Identification specificationtype:node- 该 codec 所对应的 GraphQLObjectType(type)是否应实现 GraphQL 全局对象标识(Global Object Identification)规范 -
interface:node- should the GraphQLInterfaceType (interface) this codec represents implement the GraphQL Global Object Identification specificationinterface:node- 该 codec 所对应的 GraphQLInterfaceType(interface)是否应实现 GraphQL 全局对象标识(Global Object Identification)规范 -
list- list (simple collection)list- list(简单集合列表) -
connection- connection (GraphQL Cursor Pagination Spec)connection- Connection(遵循 GraphQL Cursor 分页规范) -
query:resource:list- “list” field for a resource at the root Query levelquery:resource:list- 在根 Query 类型上为该 resource 生成“list”字段 -
query:resource:connection- “connection” field for a resource at the root Query levelquery:resource:connection- 在根 Query 类型上为该 resource 生成“Connection”字段 -
query:interface:list- “list” field for a interface at the root Query levelquery:interface:list- 在根 Query 类型上为该接口(interface)生成“list”字段 -
query:interface:connection- “connection” field for a interface at the root Query levelquery:interface:connection- 在根 Query 类型上为该接口(interface)生成“Connection”字段 -
queryField- for procedures: should it become a field on theQuerytype?queryField- 针对存储过程/函数(procedure):是否将其作为字段添加到Query类型上 -
typeField- for procedures: should it become a field on a non-operation type?typeField- 针对存储过程/函数(procedure):是否将其作为字段添加到非操作类型(即非 Query/Mutation/Subscription 类型)上 -
queryField:resource:connection- should we represent this resource with a connection on theQuerytype?queryField:resource:connection- 在Query类型上是否以 Connection 形式暴露该 resource -
queryField:resource:list- should we represent this resource with a list on theQuerytype?queryField:resource:list- 在Query类型上是否以列表(list)形式暴露该 resource -
typeField:resource:connection- should we represent this resource with a connection on a non-operation typetypeField:resource:connection- 在非操作类型上是否以 Connection 形式暴露该 resource -
typeField:resource:list- should we represent this resource with a list on a non-operation typetypeField:resource:list- 在非操作类型上是否以列表(list)形式暴露该 resource -
mutationField- for procedures: should it become a mutation (field onMutation)?mutationField- 针对存储过程/函数(procedure):是否将其作为 mutation(Mutation类型上的字段) -
order- can we sort this thing? (resource)order- 是否允许对该对象(resource)进行排序 query:resource:list:orderquery:resource:connection:order-
resource:relatedAggregates:orderBy- can we order this resource by aggregates on its relationships?resource:relatedAggregates:orderBy- 是否允许根据关联关系的聚合结果对该 resource 进行排序 -
orderBy- can we order by this thing (e.g. column)?orderBy- 是否允许按该项(如某列)进行排序 -
proc:orderBy- can we order by the result of this proc (function resource)?proc:orderBy- 是否允许按该 proc(函数型 resource)的返回值进行排序 -
attribute:orderBy- can we order by this attribute (column, property)?attribute:orderBy- 是否允许按该属性(列或字段属性)进行排序 -
attribute:aggregate:orderBy- can we order by aggregates of this attribute (column, property)?attribute:aggregate:orderBy- 是否允许按该属性(列或字段属性)的聚合结果进行排序 -
sum:attribute:aggregate:orderBy- can we order by ‘sum’ aggregates of this attribute (column, property)?sum:attribute:aggregate:orderBy- 是否允许按该属性(列或字段属性)的 ‘sum’ 聚合结果进行排序 -
filterBy- can we filter by this thing (e.g. column, table, etc)?filterBy- 是否允许按该项(如列、表等)进行过滤 -
proc:filterBy- can we filter by the result of this proc (function resource)proc:filterBy- 是否允许按该 proc(函数型 resource)的返回值进行过滤 -
attribute:filterBy- can we filter by this attribute (column, property)?attribute:filterBy- 是否允许按该属性(列或字段属性)进行过滤 -
condition:attribute:filterBy- can we filter by this attribute (column, property) in theconditionargument?condition:attribute:filterBy- 是否允许在condition参数中按该属性(列或字段属性)进行过滤 -
attribute:aggregate:filterBy- can we filter by the aggregate of this attribute (column, property)?attribute:aggregate:filterBy- 是否允许按该属性(列或字段属性)的聚合结果进行过滤 -
sum:attribute:aggregate:filterBy- can we filter by the ‘sum’ aggregate of this attribute (column, property)?sum:attribute:aggregate:filterBy- 是否允许按该属性(列或字段属性)的 ‘sum’ 聚合结果进行过滤 -
resource:aggregates:filterBy- can we filter (a different resource) by this resource's aggregates?resource:aggregates:filterBy- 是否允许根据该 resource 的聚合结果来过滤(另一个 resource) -
sum:resource:aggregates:filterBy- can we filter (a different resource) by this resource's ‘sum’ aggregates?sum:resource:aggregates:filterBy- 是否允许根据该 resource 的 ‘sum’ 聚合结果来过滤(另一个 resource) -
single- can we get just one?single- 是否支持单条记录查询 -
query:resource:single- can we get a single one of these (resource) at the root?query:resource:single- 是否允许在根 Query 上查询单条该 resource 记录 -
singularRelation:resource:single- can we get a single one of these (resource) from a type?singularRelation:resource:single- 是否允许在某个类型上获取单条关联的该 resource 记录 -
singularRelation:resource:list- should we add a list field to navigate this singular relationship (when we know there can be at most one)?singularRelation:resource:list- 当已知该一对一关系(singular relationship)最多只有一条记录时,是否仍要添加一个列表字段来导航该关系 -
singularRelation:resource:connection- should we add a connection field to navigate this singular relationship (when we know there can be at most one)?singularRelation:resource:connection- 当已知该一对一关系(singular relationship)最多只有一条记录时,是否仍要添加一个 Connection 字段来导航该关系 manyRelation:resource:listmanyRelation:resource:connection-
manyRelation:aggregates:orderBy- can we order by aggregates of this manyRelation?manyRelation:aggregates:orderBy- 是否允许按该一对多关系(manyRelation)的聚合结果进行排序 -
sum:manyRelation:aggregates:orderBy- can we order by ‘sum’ aggregates of this manyRelation?sum:manyRelation:aggregates:orderBy- 是否允许按该一对多关系(manyRelation)的 ‘sum’ 聚合结果进行排序 -
jwt- should the given codec behave as if it were a JWT?jwt- 是否将指定 codec 视为 JWT 处理 -
insert:input:record- input to the 'insert' mutationinsert:input:record- 用于 ‘insert’ mutation 的 input 类型 -
totalCount- on a codec, should we add thetotalCountfield?totalCount- 是否在 codec 对应的集合上添加totalCount字段
Fragment matching algorithm片段匹配算法
When determining if a fragment matches the filter, we use the following algorithm:
判断某个 behavior 片段是否匹配目标过滤条件(filter)时,系统采用如下算法:
ScopeMatches(fragment, filter):
ScopeMatches(fragment, filter) 伪代码步骤如下:
-
Let
filterPhrasesbefiltersplit on:.将
filter按:拆分为数组filterPhrases。 -
Let
fragmentPhrasesbe the scope offragmentsplit on:.将
fragment的作用域部分按:拆分为数组fragmentPhrases。 -
If
fragmentPhraseshas more parts thanfilterPhrases, return false.如果
fragmentPhrases的元素数量多于filterPhrases,则返回 false。 -
Let
positivebe false iffragmentstarts with-, otherwise true.若
fragment以-开头,则将positive设为 false,否则设为 true。 -
Make
fragmentPhraseshave the same length asfilterPhrasesby prepending the requisite number of*phrases to it.在
fragmentPhrases头部补充相应数量的*短语,使其与filterPhrases长度一致。 -
For each corresponding
filterPhraseandfragmentPhraseinfilterPhrasesandfragmentPhrases:逐一遍历
filterPhrases和fragmentPhrases中对应位置的filterPhrase与fragmentPhrase:-
If
filterPhraseis*,fragmentPhraseis not*, andpositiveis false; return false.如果
filterPhrase为*、fragmentPhrase不为*且positive为 false,则返回 false。 -
If neither
filterPhrasenorfragmentPhraseis*and they are not equal, return false.如果
filterPhrase与fragmentPhrase均不为*且二者不相等,则返回 false。
-
-
Return true.
返回 true。
Future expansions未来扩展方向
Would be good to add additional data, e.g. query:resource:single[pk],
query:resource:single[node], query:single[unique] could all be be added, and would
allow you to set a rule like -query:resource:single +query:single[node] to only allow
the node accessors.
未来可以考虑引入更多附加限定信息,例如新增 query:resource:single[pk]、query:resource:single[node]、query:single[unique] 等写法,从而允许通过 -query:resource:single +query:single[node] 这样的规则来仅保留基于 Node 的单条查询入口。
Behaviors to avoid应避免使用的 behavior
In order to avoid ambiguities, do not use:
为避免歧义,请勿使用以下写法:
-
create- useinsertinsteadcreate—— 请改用insert -
root:- usequery:,mutation:orsubscription:insteadroot:—— 请改用query:、mutation:或subscription:
Setting and consuming behaviors in a plugin在插件中设置和使用 behavior
TODO: document this.
TODO:待补充详细文档。
const MyPlugin = {
name: "MyPlugin",
version: "0.0.0",
schema: {
// Register default behaviors (optional)
entityBehaviors: {
// Apply 'myCodecBehavior' by default to _all_ codecs
pgCodec: "myCodecBehavior",
// Apply 'myResourceBehavior' to resources with truthy `isUnique` (overrides defaults)
pgResource(behavior, resource) {
if (resource.isUnique) {
return [behavior, "myResourceBehavior"];
} else {
return behavior;
}
},
},
// Do something with behaviors (optional)
hooks: {
GraphQLObjectType_fields_field(field, build, context) {
const codec = context.scope.pgFieldCodec;
if (
!codec ||
!build.behavior.pgCodecMatches(codec, "myCodecBehavior")
) {
return field;
}
// Behavior matches! Do stuff here...
return field;
},
},
},
};