diff --git a/examples/cpp/sync/call-function.cpp b/examples/cpp/sync/call-function.cpp index f8207c85157..9cf119199c8 100644 --- a/examples/cpp/sync/call-function.cpp +++ b/examples/cpp/sync/call-function.cpp @@ -5,15 +5,6 @@ static const std::string APP_ID = "cpp-tester-uliix"; -// This test is currently commented out because the SDK has removed the -// exposed Core headers that gave it access to a BSON library. -// See PR https://github.com/realm/realm-cpp/pull/123/ -// Per Lee, a separate project will create a C++ SDK BSON library, but in -// the meantime, I'll need to use some other library to make this test work. -// I need to figure out how to create BSON strings in C++ and pass them -// instead of using realm::bson::Bson for the params. -// TODO: Figure out what library to use and how to make this test/example work. -#if 0 TEST_CASE("call a function", "[realm][sync]") { // :snippet-start: call-a-function // Connect to an App Services App and authenticate a user @@ -25,24 +16,21 @@ TEST_CASE("call a function", "[realm][sync]") { auto user = app.login(realm::App::credentials::anonymous()).get(); auto sync_config = user.flexible_sync_configuration(); - // If a function takes arguments, pass them as BSON - auto arg1 = realm::bson::Bson("john.smith"); - auto arg2 = realm::bson::Bson("@companyemail.com"); + // If the function takes arguments, pass them as a string array. + // Any quotes within the array must be escaped. + auto argArray = "[\"john.smith\", \"@companyemail.com\"]"; // Call an App Services function as the logged-in user - auto result = user.call_function("concatenate", {arg1, arg2}).get(); + auto result = user.call_function("concatenate", argArray).get(); // Verify that the result has a value CHECK(result); - auto bsonResult = result.value(); + auto functionResult = result.value(); - // Translate the BSON result back to a string - auto resultString = std::string(bsonResult); // Prints "Calling the concatenate function returned - // john.smith@companyemail.com." - std::cout << "Calling the concatenate function returned " << resultString + // "john.smith@companyemail.com"." + std::cout << "Calling the concatenate function returned " << functionResult << ".\n"; // :snippet-end: - REQUIRE(resultString == "john.smith@companyemail.com"); + REQUIRE(functionResult == "\"john.smith@companyemail.com\""); } -#endif \ No newline at end of file diff --git a/source/examples/generated/cpp/call-function.snippet.call-a-function.cpp b/source/examples/generated/cpp/call-function.snippet.call-a-function.cpp index 4a8b2b4a4b9..f222b8ac916 100644 --- a/source/examples/generated/cpp/call-function.snippet.call-a-function.cpp +++ b/source/examples/generated/cpp/call-function.snippet.call-a-function.cpp @@ -5,20 +5,18 @@ auto app = realm::App(appConfig); auto user = app.login(realm::App::credentials::anonymous()).get(); auto sync_config = user.flexible_sync_configuration(); -// If a function takes arguments, pass them as BSON -auto arg1 = realm::bson::Bson("john.smith"); -auto arg2 = realm::bson::Bson("@companyemail.com"); +// If the function takes arguments, pass them as a string array. +// Any quotes within the array must be escaped. +auto argArray = "[\"john.smith\", \"@companyemail.com\"]"; // Call an App Services function as the logged-in user -auto result = user.call_function("concatenate", {arg1, arg2}).get(); +auto result = user.call_function("concatenate", argArray).get(); // Verify that the result has a value CHECK(result); -auto bsonResult = result.value(); +auto functionResult = result.value(); -// Translate the BSON result back to a string -auto resultString = std::string(bsonResult); // Prints "Calling the concatenate function returned -// john.smith@companyemail.com." -std::cout << "Calling the concatenate function returned " << resultString +// "john.smith@companyemail.com"." +std::cout << "Calling the concatenate function returned " << functionResult << ".\n"; diff --git a/source/sdk/cpp/app-services/call-a-function.txt b/source/sdk/cpp/app-services/call-a-function.txt index 6d8f7b23420..ce7089a02d2 100644 --- a/source/sdk/cpp/app-services/call-a-function.txt +++ b/source/sdk/cpp/app-services/call-a-function.txt @@ -39,11 +39,10 @@ To execute a function from the C++ SDK, use the :cpp-sdk:`call_function() ` member function on the ``user`` object. Pass in the name of the function as a string for the first parameter. This function takes two arguments, -which we provide as a ``BsonArray`` of arguments: +which we provide as a string array of arguments: .. literalinclude:: /examples/generated/cpp/call-function.snippet.call-a-function.cpp :language: cpp -The callback can provide an optional BSON result, or an optional error. -In the example above, we check that the result has a value, and then cast -it back to a string. +The callback can provide an optional string result, or an optional error. +In the example above, we check that the result has a value.