graphql-engine/v3/crates/frontends/graphql
Daniel Chambers f68438b78e Support receiving JSON values from Webhooks/JWT/NoAuth instead of just strings (#1257)
### What

Previously, we only supported String as the type that contained your
session variable value when they are provided from webhooks/JWT/NoAuth.
We then coerced that value into whatever type was actually expected (eg
a float) later.

However, when we added support for array-typed session variables (#1221)
we didn't actually allow you to provide a JSON array of values as a
session variable value. You had to provide a string that contained a
JSON-encoded array of values. This meant that webhooks/JWT/NoAuth had to
double JSON-encode their session variables when returning them.

This PR fixes this and makes it so that webhooks/JWT/NoAuth can return
JSON values for session variables and that JSON is respected. So if a
session variable needs to be an array of integers, they can simply
return the JSON array of integers as the value for that session
variable.

### How

Instead of holding a `SessionVariableValue` as a `String`, we now turn
that into an enum where we have an "unparsed" String (used for when we
don't receive JSON, we just receive a string value (ie. http headers)),
or a "parsed" JSON value. When we receive session variables from
webhooks/JWT/NoAuth, we relax the restriction that they can only return
us JSON strings, and instead allow them to return JSON Values, which we
put in the new `SessionVariableValue::Parsed` enum variant. HTTP headers
go into `SessionVariableValue::Unparsed`.

Then, when we go to get the required value from the
`SessionVariableValue` based on the desired type, we either parse it out
of the "unparsed" String, or we expect that the value is already in the
correct form in the "parsed" JSON value. This is the behaviour you will
get if JSON session variables are turned on in the Flags.

If JSON session variables are not turned on, then we expect that only
String session variables (parsed or unparsed) are provided from
headers/webhooks/JWT/NoAuth, and so we run the old logic of always
expecting a String and parsing the correct value out of it.

V3_GIT_ORIGIN_REV_ID: b6734ad5443b7d68065f91aea71386c893aa7eba
2024-10-22 11:46:37 +00:00
..
benches Rename schema crate to graphql-schema (#1117) 2024-09-17 20:07:06 +00:00
src Support receiving JSON values from Webhooks/JWT/NoAuth instead of just strings (#1257) 2024-10-22 11:46:37 +00:00
tests subscriptions: respect allow_subscriptions in select permissions (#1235) 2024-10-17 16:18:09 +00:00
Cargo.toml Move NdcFieldAlias to new plan-types crate (#1161) 2024-09-27 09:00:10 +00:00
readme.md frontends/graphql crate (#1049) 2024-09-10 15:44:43 +00:00

graphql frontend

The "front door" for executing a graphql query, as such