supabase-community / supabase-kt

A Kotlin Multiplatform Client for Supabase.
https://supabase.com/docs/reference/kotlin/introduction
MIT License
407 stars 37 forks source link

[Question]: How can I add Object keys as CLI in Edge Functions #630

Closed clwater closed 4 months ago

clwater commented 4 months ago

General info

What is your question?

In edge functions I accept params as {"keyA": "v1", "keys":{"keyB1", "vb1", "keyB2": "vb2"}} when I check this as CLI I used curl xxx --data '{"keyA": "v1", "keys":{"keyB1", "vb1", "keyB2": "vb2"}}'

And I can accept this and check as console.log("keyA: " + keyA) console.log("keys['keyB1']: " + keys['keyB1']) This is no problem. But when I used in Android I try used as

val result = mFunctions.invoke( function = edge_path, body = buildJsonObject { put("keyA", "v1") put("keys", Gson().toJson("Class base as keys")) }, )

But this edge function can't run right.

As blow log file. When I request as CLI, the functions log is keys: [object Object]

but when I rqeuest in Android this log is keys: {"keyB1":"v1"} I know I am used different edge request params method.

But I can't find different explain in https://supabase.com/docs/guides/functions or https://supabase.com/docs/reference/kotlin/functions-invoke

What differnet between this , Or How can I make this as same format In Android ?

Thanks

Relevant log output (optional)

keys: [object Object]

keys: {"keyB1":"v1"}
jan-tennert commented 4 months ago

I'm not sure if I understand the question. So you essentially want to put another class (serialized as a json object) in under the key keys but the result is not a JsonObject and rather a String? I assume Gson().toJson() returns a string, so the value will obviously also be a string. You could try this:

put("keys", Json.decodeFromString<JsonObject>(Gson().toJson("your content")))

This will put in an actual Json Object as the value.

clwater commented 4 months ago

As you understand, My question is I want put a class rather a String.

I try you suggest, It is useful.

Thanks

jan-tennert commented 4 months ago

@clwater I suppose then this issue has been resolved?

clwater commented 4 months ago

Yes, It is resloved