Replies: 10 comments
-
You need add " as first and last symbol |
Beta Was this translation helpful? Give feedback.
-
I am well aware of what I need to do -- but I think the API as it is today is not great, and makes debugging a simple mistake way too hard. I'd love to know more about the intent behind that MarshalGQL API; I feel like I personally would have just passed things to json.Marshal, and let them have MarshalJSON methods if they want. I understand GraphQL might need something special on the unmarshal side (inputs can come from either inside the query or JSON, but that sounds like you can pretend they're JSON in either case because that compatibility has to exist anyway). But for the marshaling -- even if you can make the argument that GraphQL pretends to be independent of JSON, the current io.Writer-based API is tying things down to a specific wire format anyway. |
Beta Was this translation helpful? Give feedback.
-
Aliases are the main thing that prevent using json.Marshal, the same field can be present multiple times with different names and different args. Can't use maps either as the request determined order. The outer json marshal will be removed soon, which is what is generating this error. Once that's gone you will get the same behaviour you would from a broken custom marshal func with json.marshal - bad json |
Beta Was this translation helpful? Give feedback.
-
That's not what encoding/json does, though: https://play.golang.org/p/Sz_7cJx4pBl |
Beta Was this translation helpful? Give feedback.
-
I wish I understood what "same field being present multiple times" means. |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
-
Hey stale bot, just because bugs are not fixed, or they are flagged as "question" for some reason, doesn't mean they're fixed. |
Beta Was this translation helpful? Give feedback.
-
I suspect you can replicate this issue with: #1195. which would imply you can send a valid go float value into your GQL and cause a panic with invalid JSON. |
Beta Was this translation helpful? Give feedback.
-
I am having what looks like the same issue:
From a simple bit of testing code that I put together after read the same page:
I however have no idea how to resolve this issues? |
Beta Was this translation helpful? Give feedback.
-
At the minimum you could check for errors, and log them or defer and recover from any panics. Falling back to some default, such as func MarshalMatrix(s CustomStr) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
// to recover from panics..
defer func() {
if err := recover(); err != nil {
// I would log a panic occurred,
// ...
// but still return null..
w.Write([]byte(`null`))
}
}()
// Do stuff which could error...
_, err := io.WriteString(w, strconv.Quote(s))
if err != nil {
// log errror occured
// ..
// fallback
w.Write([]byte(`null`))
}
})
} For your specific issue @utx0 you need to provide a valid json string using |
Beta Was this translation helpful? Give feedback.
-
What happened?
A custom scalar MarshqlGQL implementation triggered the following, by outputting a string instead of a JSON-quoted string. None of my relevant code was in the stack trace; after the copy-paste bit is just me starting the http server.
What did you expect?
versions
gqlgen version
: v0.10.1go version
? go version go1.13.3 linux/amd64Beta Was this translation helpful? Give feedback.
All reactions