Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Client: GraphQL package #328

Merged
merged 7 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.weaviate.client.v1.async.classifications.Classifications;
import io.weaviate.client.v1.async.cluster.Cluster;
import io.weaviate.client.v1.async.data.Data;
import io.weaviate.client.v1.async.graphql.GraphQL;
import io.weaviate.client.v1.async.misc.Misc;
import io.weaviate.client.v1.async.schema.Schema;
import io.weaviate.client.v1.misc.model.Meta;
Expand Down Expand Up @@ -60,6 +61,10 @@ public Backup backup() {
return new Backup(client, config);
}

public GraphQL graphQL() {
return new GraphQL(client, config);
}

private DbVersionProvider initDbVersionProvider() {
DbVersionProvider.VersionGetter getter = () ->
Optional.ofNullable(this.getMeta())
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/io/weaviate/client/v1/async/graphql/GraphQL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.weaviate.client.v1.async.graphql;

import io.weaviate.client.Config;
import io.weaviate.client.v1.async.graphql.api.Aggregate;
import io.weaviate.client.v1.async.graphql.api.Explore;
import io.weaviate.client.v1.async.graphql.api.Get;
import io.weaviate.client.v1.async.graphql.api.Raw;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;

public class GraphQL {
private final Config config;
private final CloseableHttpAsyncClient client;

public GraphQL(CloseableHttpAsyncClient client, Config config) {
this.client = client;
this.config = config;
}

public Get get() {
return new Get(client, config);
}

public Raw raw() {
return new Raw(client, config);
}

public Explore explore() {
return new Explore(client, config);
}

public Aggregate aggregate() {
return new Aggregate(client, config);
}

public io.weaviate.client.v1.graphql.GraphQL.Arguments arguments() {
return new io.weaviate.client.v1.graphql.GraphQL.Arguments();
}
}
126 changes: 126 additions & 0 deletions src/main/java/io/weaviate/client/v1/async/graphql/api/Aggregate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package io.weaviate.client.v1.async.graphql.api;

import io.weaviate.client.Config;
import io.weaviate.client.base.AsyncBaseClient;
import io.weaviate.client.base.AsyncClientResult;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.filters.WhereFilter;
import io.weaviate.client.v1.graphql.model.GraphQLQuery;
import io.weaviate.client.v1.graphql.model.GraphQLResponse;
import io.weaviate.client.v1.graphql.query.argument.*;
import io.weaviate.client.v1.graphql.query.builder.AggregateBuilder;
import io.weaviate.client.v1.graphql.query.fields.Field;
import io.weaviate.client.v1.graphql.query.fields.Fields;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;

import java.util.concurrent.Future;

public class Aggregate extends AsyncBaseClient<GraphQLResponse> implements AsyncClientResult<GraphQLResponse> {
private final AggregateBuilder.AggregateBuilderBuilder aggregateBuilder;

public Aggregate(CloseableHttpAsyncClient client, Config config) {
super(client, config);
aggregateBuilder = AggregateBuilder.builder();
}

public Aggregate withClassName(String className) {
aggregateBuilder.className(className);
return this;
}

public Aggregate withFields(Field... fields) {
aggregateBuilder.fields(Fields.builder()
.fields(fields)
.build());
return this;
}

@Deprecated
public Aggregate withWhere(WhereFilter where) {
return withWhere(WhereArgument.builder()
.filter(where)
.build());
}

public Aggregate withWhere(WhereArgument where) {
aggregateBuilder.withWhereFilter(where);
return this;
}

public Aggregate withGroupBy(String propertyName) {
aggregateBuilder.groupByClausePropertyName(propertyName);
return this;
}

public Aggregate withAsk(AskArgument ask) {
aggregateBuilder.withAskArgument(ask);
return this;
}

public Aggregate withNearText(NearTextArgument withNearTextFilter) {
aggregateBuilder.withNearTextFilter(withNearTextFilter);
return this;
}

public Aggregate withNearObject(NearObjectArgument withNearObjectFilter) {
aggregateBuilder.withNearObjectFilter(withNearObjectFilter);
return this;
}

public Aggregate withNearVector(NearVectorArgument withNearVectorFilter) {
aggregateBuilder.withNearVectorFilter(withNearVectorFilter);
return this;
}

public Aggregate withNearImage(NearImageArgument nearImage) {
aggregateBuilder.withNearImageFilter(nearImage);
return this;
}

public Aggregate withNearAudio(NearAudioArgument nearAudio) {
aggregateBuilder.withNearAudioFilter(nearAudio);
return this;
}

public Aggregate withNearVideo(NearVideoArgument nearVideo) {
aggregateBuilder.withNearVideoFilter(nearVideo);
return this;
}

public Aggregate withNearDepth(NearDepthArgument nearDepth) {
aggregateBuilder.withNearDepthFilter(nearDepth);
return this;
}

public Aggregate withNearThermal(NearThermalArgument nearThermal) {
aggregateBuilder.withNearThermalFilter(nearThermal);
return this;
}

public Aggregate withNearImu(NearImuArgument nearImu) {
aggregateBuilder.withNearImuFilter(nearImu);
return this;
}

public Aggregate withObjectLimit(Integer objectLimit) {
aggregateBuilder.objectLimit(objectLimit);
return this;
}

public Aggregate withTenant(String tenant) {
aggregateBuilder.tenant(tenant);
return this;
}

@Override
public Future<Result<GraphQLResponse>> run(FutureCallback<Result<GraphQLResponse>> callback) {
String aggregateQuery = aggregateBuilder.build()
.buildQuery();
GraphQLQuery query = GraphQLQuery.builder()
.query(aggregateQuery)
.build();
return sendPostRequest("/graphql", query, GraphQLResponse.class, callback);
}

}
99 changes: 99 additions & 0 deletions src/main/java/io/weaviate/client/v1/async/graphql/api/Explore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package io.weaviate.client.v1.async.graphql.api;

import io.weaviate.client.Config;
import io.weaviate.client.base.AsyncBaseClient;
import io.weaviate.client.base.AsyncClientResult;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.graphql.model.ExploreFields;
import io.weaviate.client.v1.graphql.model.GraphQLQuery;
import io.weaviate.client.v1.graphql.model.GraphQLResponse;
import io.weaviate.client.v1.graphql.query.argument.*;
import io.weaviate.client.v1.graphql.query.builder.ExploreBuilder;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;

import java.util.concurrent.Future;

public class Explore extends AsyncBaseClient<GraphQLResponse> implements AsyncClientResult<GraphQLResponse> {
private final ExploreBuilder.ExploreBuilderBuilder exploreBuilder;

public Explore(CloseableHttpAsyncClient client, Config config) {
super(client, config);
exploreBuilder = ExploreBuilder.builder();
}

public Explore withFields(ExploreFields... fields) {
exploreBuilder.fields(fields);
return this;
}

public Explore withLimit(Integer limit) {
exploreBuilder.limit(limit);
return this;
}

public Explore withOffset(Integer offset) {
exploreBuilder.offset(offset);
return this;
}

public Explore withAsk(AskArgument ask) {
exploreBuilder.withAskArgument(ask);
return this;
}

public Explore withNearText(NearTextArgument nearText) {
exploreBuilder.withNearText(nearText);
return this;
}

public Explore withNearObject(NearObjectArgument nearObject) {
exploreBuilder.withNearObjectFilter(nearObject);
return this;
}

public Explore withNearVector(NearVectorArgument nearVector) {
exploreBuilder.withNearVectorFilter(nearVector);
return this;
}

public Explore withNearImage(NearImageArgument nearImage) {
exploreBuilder.withNearImageFilter(nearImage);
return this;
}

public Explore withNearAudio(NearAudioArgument nearAudio) {
exploreBuilder.withNearAudioFilter(nearAudio);
return this;
}

public Explore withNearVideo(NearVideoArgument nearVideo) {
exploreBuilder.withNearVideoFilter(nearVideo);
return this;
}

public Explore withNearDepth(NearDepthArgument nearDepth) {
exploreBuilder.withNearDepthFilter(nearDepth);
return this;
}

public Explore withNearThermal(NearThermalArgument nearThermal) {
exploreBuilder.withNearThermalFilter(nearThermal);
return this;
}

public Explore withNearImu(NearImuArgument nearImu) {
exploreBuilder.withNearImuFilter(nearImu);
return this;
}

@Override
public Future<Result<GraphQLResponse>> run(FutureCallback<Result<GraphQLResponse>> callback) {
String exploreQuery = exploreBuilder.build()
.buildQuery();
GraphQLQuery query = GraphQLQuery.builder()
.query(exploreQuery)
.build();
return sendPostRequest("/graphql", query, GraphQLResponse.class, callback);
}
}
Loading
Loading