GraphQl

GraphQl

The GraphQl interface provides GraphQl query and mutation functionality.

From SDK version 1.11.0 all functions provided in the GraphQl interface returning LiveData are deprecated. They will be removed in SDK version 1.13.0! Use either the suspend functions with Coroutines or one of the alternative functions that takes a callback lambda as parameter and return Cancelable.

You should use the default functions using Kotlin Coroutines:

val exampleAppQuery: ExampleAppQuery = ExampleAppQuery.builder().build()

fragmentScope.launch {
	smartSpacesSdk.getGraphQl()
		.query(exampleAppQuery)
		.collect { result ->
			result.errors.forEach { error ->
				// do something with the errors
			}

			result.data?.let { data ->
				// do something with the data
			}
		}
}

If you can’t use Coroutines or you are programming Java only, you can use the corresponding functions using Callback:

val cancelable: Cancelable = smartSpacesSdk
	.getGraphQl()
	.queryWithCallback(exampleAppQuery) { result: Result<ExampleAppQuery.Data> ->
		// do something with the result
}

You can pass an optional updateIntervalMillis parameter to the query functions. It will constantly trigger that query in the given interval.

Do not forget calling cancel() on the CoroutineScope or the Cancelable or you will leak memory!