Skip to content

Commit

Permalink
Add localClient bean.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Griffin committed Nov 20, 2024
1 parent 4026008 commit 8634c04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/fauna/sample/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
import com.fauna.client.FaunaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
class AppConfig {

@Bean
@Profile("!local")
FaunaClient faunaClient() {
// Creates a `FaunaClient` with its default configuration. Note that by
// default it looks for `FAUNA_ENDPOINT` and `FAUNA_SECRET` environment
// variables in oder to determine which endpoint and secret ot use. If
// the endpoint is not set, it uses `https://db.fauna.com`.
return Fauna.client();
}

@Bean
@Profile("local")
FaunaClient localClient() {
return Fauna.local();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fauna.sample.controllers.products;

import com.fauna.client.FaunaClient;
import com.fauna.query.QueryOptions;
import com.fauna.query.builder.Query;
import com.fauna.response.QuerySuccess;
import com.fauna.types.Page;
Expand All @@ -13,6 +14,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -90,7 +92,8 @@ Future<Page<Product>> paginate(
// as a parameter as well as an optional return type. In this case, we are
// using the Product.class to specify that the query will return a single
// item representing a Product.
return CompletableFuture.completedFuture(client.paginate(query, Product.class).next());
return CompletableFuture.completedFuture(client.paginate(query, Product.class,
QueryOptions.builder().timeout(Duration.ofSeconds(30)).build()).next());
}

@Async
Expand Down

0 comments on commit 8634c04

Please sign in to comment.