Comments (7)
Can you explain more about what isn't working and why json:"-"
is causing problems? Are you seeing actual serialization errors? Anytime genqlient adds that it should also add appropriate MarshalJSON
/UnmarshalJSON
(in this case to Webhook
) to ensure everything serializes correctly.
from genqlient.
When I look at the code there is a marshal and unmashal, but when I use the Webhook inside Temporal (passes json between activities) then it does not encode the json.
// Webhook includes the requested fields of the GraphQL type Webhook.
type Webhook struct {
webhookFields `json:"-"`
}
// GetId returns Webhook.Id, and is useful for accessing the field via an interface.
func (v *Webhook) GetId() string { return v.webhookFields.Id }
// GetName returns Webhook.Name, and is useful for accessing the field via an interface.
func (v *Webhook) GetName() string { return v.webhookFields.Name }
// GetSource returns Webhook.Source, and is useful for accessing the field via an interface.
func (v *Webhook) GetSource() string { return v.webhookFields.Source }
// GetEnabled returns Webhook.Enabled, and is useful for accessing the field via an interface.
func (v *Webhook) GetEnabled() bool { return v.webhookFields.Enabled }
// GetCreatedAt returns Webhook.CreatedAt, and is useful for accessing the field via an interface.
func (v *Webhook) GetCreatedAt() time.Time { return v.webhookFields.CreatedAt }
func (v *Webhook) UnmarshalJSON(b []byte) error {
if string(b) == "null" {
return nil
}
var firstPass struct {
*Webhook
graphql.NoUnmarshalJSON
}
firstPass.Webhook = v
err := json.Unmarshal(b, &firstPass)
if err != nil {
return err
}
err = json.Unmarshal(
b, &v.webhookFields)
if err != nil {
return err
}
return nil
}
type __premarshalWebhook struct {
Id string `json:"id"`
Name string `json:"name"`
Source string `json:"source"`
Enabled bool `json:"enabled"`
CreatedAt time.Time `json:"createdAt"`
}
func (v *Webhook) MarshalJSON() ([]byte, error) {
premarshaled, err := v.__premarshalJSON()
if err != nil {
return nil, err
}
return json.Marshal(premarshaled)
}
func (v *Webhook) __premarshalJSON() (*__premarshalWebhook, error) {
var retval __premarshalWebhook
retval.Id = v.webhookFields.Id
retval.Name = v.webhookFields.Name
retval.Source = v.webhookFields.Source
retval.Enabled = v.webhookFields.Enabled
retval.CreatedAt = v.webhookFields.CreatedAt
return &retval, nil
}
If I write a hack for it, it does not trigger
func main() {
webhook := graphql.Webhook{}
webhook.Name = "Cookie"
webhook.CreatedAt = time.Now()
_, j := json.Marshal(webhook)
log.Printf("json=%s", j)
}
> go run main.go
2024/02/21 14:23:19 json=%!s(<nil>)
from genqlient.
I can not explain why it works, but if I remove the json:"-"
then it seems to serialize fine within Temporal. I did however make my own serialization class to ensure it would not end up not serializing on future changes (regenerations).
from genqlient.
Ah, you probably want to pass a pointer (&webhook
) so the receiver works. That tends to be the convention for anything JSON, although maybe we could make it a value receiver so it doesn't matter? That might require some research, not sure if there are perf or complexity issues.
from genqlient.
I do unfortunately not determine how temporal passes data between workers/activities, so right now I use the middleware struct (basically a copy of the root/internal struct). It would be interesting if this somehow could be worked out :D
from genqlient.
Can you not pass the pointer in? Does Temporal dereference the pointer?
In any case, I think you'll need to give a more complete example of what your code is doing with Temporal for us to help. In the code you listed, the fix is to pass a pointer. If that's not what your code is really doing, many other problems could be at play, whether with genqlient or Temporal.
from genqlient.
I'm sorry for never getting back to you, a few things have changed and I will soon no longer have access to this code I am working on. Due to its work relation I am unable to make you a replicate of my issue. If I encounter it in my own project then I will return with example repo if possible. I will close my issue due to this change of accessibility.
from genqlient.
Related Issues (20)
- Does the genqlient support extensions on requests? HOT 1
- Errors with Strawberry Generated Schema including `JSON` Scalar HOT 1
- Tests failing on Go 1.22+
- Lint failing on 1.21+
- Support `optional: generic` inline
- Support, new release HOT 1
- How can I get response header HOT 1
- Allow globs for schema/queries to be optional, if at least one file is found HOT 1
- Inconsistent JSON Tag Generation for Required Boolean Fields in Structs HOT 3
- Optional input with required output HOT 1
- Support for @authenticated directive HOT 2
- Standardise the error return from http request HOT 3
- Add option to not generate the client, only the types HOT 2
- Option to generate multiple files HOT 2
- Using an Interface inline fragment inside of a Union is awkward to unpack HOT 3
- Optional parameter made required HOT 2
- schema.md has some formatting issues
- Running genqlient on large schemas fails HOT 4
- use_struct_references not compatible with new omitempty validation logic HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from genqlient.