Closed zaneli closed 1 month ago
@zaneli Thanks ! I'm glad to know about this issue. Currently, there are other issues with the parser, and I will try to fix them together with those issues.
I tried to use v0.21.1 and the problem does not appear to be fixed. The following test fail.
{
name: "marshal Request",
args: args{
v: &Request{
Query: `{ query(input: $input) }`,
Variables: map[string]interface{}{"input": NumberOne},
OperationName: "Test",
},
},
want: []byte(`{"query":"{ query(input: $input) }","variables":{"input":"ONE"},"operationName":"Test"}`),
},
--- FAIL: TestMarshalJSON (0.00s)
--- FAIL: TestMarshalJSON/marshal_Request (0.00s)
gqlgenc/clientv2/client_test.go:675: MarshalJSON() got = map[operationName:Test query:{ query(input: $input) } variables:map[input:1]], want map[operationName:Test query:{ query(input: $input) } variables:map[input:ONE]]
I also think there is a similar problem with unmarshalling. I hope this test will be successful.
func TestUnmarshalGQL(t *testing.T) {
c := &Client{}
type Example struct {
Name string `json:"name"`
Number Number `json:"number"`
}
var got Example
if err := c.unmarshal([]byte(`{"data": {"name": "test", "number": "ONE"}}`), &got); err != nil {
t.Fatalf("Failed to unmarshal: %v", err)
}
want := Example{
Name: "test",
Number: NumberOne,
}
if !cmp.Equal(got, want) {
t.Fatalf("c.unmarshal() got = %v, want %v", got, want)
}
}
--- FAIL: TestUnmarshalGQL (0.00s)
gqlgenc/clientv2/client_test.go:689: Failed to unmarshal: failed to decode data into response {"data": {"name": "test", "number": "ONE"}}: : : : : json: cannot unmarshal string into Go value of type clientv2.Number
@Yamashou not yet?
@kyoh86 sorry. I have not been able to finish my day job and have not gotten around to it. I have about 20% to complete.
@zaneli @kyoh86 Implemented support for arguments! https://github.com/Yamashou/gqlgenc/releases/tag/v0.23.2
I have verified that this problem has been fixed. Thank you for fixing it!
It seems like gqlgenc doesn't take
MarshalGQL
method into account.It works fine.
However, gqlgenc generated codes seem to not use
MarshalGQL
method.https://github.com/Yamashou/gqlgenc/blob/484c08b959ce132e110b0e74b7eb44eb396f6e36/clientv2/client.go#L185
I realized that there is a workaround to implement
MarshalJSON
method as well.After implement
MarshalJSON
,TestEnumToNum
succeeded.