hasura / hasura/graphql-engine
Event Triggers: Camel case naming conventions not applied to the event payload
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: v2.11.1
### Environment
All environments
### What is the current behaviour?
If the `graphql-default` naming convention is enabled as described here: https://hasura.io/docs/latest/schema/postgres/naming-convention/ event trigger payloads will not have the columns camel cased.
Example payload when the `graphql-default` naming convention is enabled:
```
{
"event": {
"op": "INSERT",
"data": {
"old": null,
"new": {
"first_name": "First",
"last_name": "Last",
}
}
},
{...the rest of the payload}
}
```
### What is the expected behaviour?
I am using a Nest.js API backend to handle the event trigger payloads. In addition, I am using graphql-codegen to generate typescript types for my schema to be used on the backend.
Here is an example of how I am using this together with hasura events:
```
@TrackedHasuraEventHandler({
triggerName: "user-created",
tableName: "user",
definition: { type: "insert" },
})
public async createUser({ event }: HasuraInsertEvent) {} // The "User" type contains all camelCased columns from hasura introspection
```
Since the payload is not camel cased, the generated types are inconsistent with what I am expecting and the output of introspection. In other words, I am unable to guarantee type-safety on my API.
Here is a payload I would expect when using the `graphql-default` naming convention:
```
{
"event": {
"op": "INSERT",
"data": {
"old": null,
"new": {
"firstName": "First",
"lastLame": "Last",
}
}
},
{...the rest of the payload}
}
```
### How to reproduce the issue?
1. Enable the `graphql-default` naming standard following the docs here: https://hasura.io/docs/latest/schema/postgres/naming-convention/
2. Create an event trigger on any table for any event type (INSERT, UPDATE, etc.)
3. Trigger the event.
4. When handling the event payload in some other service, the columns will not be renamed according to the naming standard enforced by Hasura.
### Any possible solutions?
In the meantime, I have manually added event trigger payload transforms. For example:
```
{
"event": {
"op": "INSERT",
"data": {
"old": null,
"new": {
"firstName": {{$body.data.new.first_name}},
"lastName": {{$body.data.new.last_name}},
}
},
"trace_context": {{$body.event.trace_context}}
},
"created_at": {{$body.created_at}},
"id": {{$body.id}},
"delivery_info": {{$body.delivery_info}},
"trigger": {{$body.trigger}},
"table": {{$body.table}}
}
```
### Keywords
Hasura, naming convention, graphql-default, event triggers, camel case, event payload
Contributor guide
Assessment
This issue has not been assessed yet.