Skip to content
Open
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
4 changes: 4 additions & 0 deletions gremlin-dart/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dart_tool/
build/
.packages
doc/api/
32 changes: 32 additions & 0 deletions gremlin-dart/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

services:
gremlin-server:
build:
context: ./docker
dockerfile: Dockerfile
container_name: gremlin-server-dart
ports:
- "45940:45940"
command: ["conf/gremlin-server-dart.yaml"]
healthcheck:
test: ["CMD-SHELL", "curl -sf -X POST -H 'Content-Type: application/json' -d '{\"gremlin\":\"g.inject(1)\",\"g\":\"gmodern\"}' http://localhost:45940/gremlin"]
interval: 10s
timeout: 5s
retries: 15
start_period: 20s
21 changes: 21 additions & 0 deletions gremlin-dart/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

FROM tinkerpop/gremlin-server:4.0.0-beta.2
COPY gremlin-server-dart.yaml /opt/gremlin-server/conf/gremlin-server-dart.yaml
COPY tinkergraph-service.properties /opt/gremlin-server/conf/tinkergraph-service.properties
COPY load-test-graphs.groovy /opt/gremlin-server/scripts/load-test-graphs.groovy
45 changes: 45 additions & 0 deletions gremlin-dart/docker/gremlin-server-dart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

host: 0.0.0.0
port: 45940
evaluationTimeout: 30000
channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer
graphs: {
graph: conf/tinkergraph-service.properties,
modern: conf/tinkergraph-service.properties,
classic: conf/tinkergraph-service.properties,
crew: conf/tinkergraph-service.properties,
grateful: conf/tinkergraph-service.properties,
sink: conf/tinkergraph-service.properties}
scriptEngines: {
gremlin-lang: {},
gremlin-groovy: {
plugins: {
org.apache.tinkerpop.gremlin.server.jsr223.GremlinServerGremlinPlugin: {},
org.apache.tinkerpop.gremlin.tinkergraph.jsr223.TinkerGraphGremlinPlugin: {},
org.apache.tinkerpop.gremlin.jsr223.ScriptFileGremlinPlugin: {
files: [scripts/load-test-graphs.groovy]}}}}
serializers:
- { className: org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV4 }
- { className: org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV4 }
- { className: org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV4, config: { serializeResultToString: true }}
metrics: {
slf4jReporter: {enabled: true, interval: 180000}}
gremlinPool: 8
strictTransactionManagement: false
resultIterationBatchSize: 64
35 changes: 35 additions & 0 deletions gremlin-dart/docker/load-test-graphs.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory

TinkerFactory.generateModern(modern)
TinkerFactory.generateClassic(classic)
TinkerFactory.generateTheCrew(crew)
TinkerFactory.generateGratefulDead(grateful)
TinkerFactory.generateKitchenSink(sink)

def globals = [:]
globals << [g : traversal().withEmbedded(graph)]
globals << [ggraph : traversal().withEmbedded(graph)]
globals << [gmodern : traversal().withEmbedded(modern)]
globals << [gclassic: traversal().withEmbedded(classic)]
globals << [gcrew : traversal().withEmbedded(crew)]
globals << [ggrateful: traversal().withEmbedded(grateful)]
globals << [gsink : traversal().withEmbedded(sink)]
23 changes: 23 additions & 0 deletions gremlin-dart/docker/tinkergraph-service.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
gremlin.tinkergraph.vertexIdManager=INTEGER
gremlin.tinkergraph.edgeIdManager=INTEGER
gremlin.tinkergraph.vertexPropertyIdManager=LONG
gremlin.tinkergraph.service=org.apache.tinkerpop.gremlin.tinkergraph.services.TinkerTextSearchFactory
gremlin.tinkergraph.service=org.apache.tinkerpop.gremlin.tinkergraph.services.TinkerDegreeCentralityFactory
52 changes: 52 additions & 0 deletions gremlin-dart/example/basic.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0

import 'package:gremlin_dart/gremlin_dart.dart';

Future<void> main() async {
final conn = DriverRemoteConnection('http://localhost:8182/gremlin');

// g is the graph traversal source — all queries start here
final g = traversal().withRemote(conn);

// Buffered query: returns Future<List<T>>
final vertices = await g.V().hasLabel('person').toList();
print('People: $vertices');

// Chained property access
final names = await g.V().hasLabel('person').values(['name']).toList<String>();
print('Names: $names');

// Anonymous traversal inside repeat
final reachable = await g
.V()
.has('name', P.eq('marko'))
.repeat(Anon.out(['knows']))
.times(2)
.values(['name'])
.toList<String>();
print('Reachable from marko in 2 hops: $reachable');

// Streaming query
await for (final item in g.V().hasLabel('software').stream()) {
print(' software: $item');
}

await conn.close();
}

extension StreamingTraversal on GraphTraversal {
// Convenience extension so callers can do g.V()...stream()
Stream<dynamic> stream() {
return Stream.fromFuture(applyStrategies()).asyncExpand((_) {
return resultsStream ?? const Stream.empty();
});
}
}
25 changes: 25 additions & 0 deletions gremlin-dart/lib/driver/auth.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0

import 'dart:convert';

abstract class AuthOptions {}

class BasicAuth extends AuthOptions {
final String username;
final String password;

BasicAuth({required this.username, required this.password});

String get headerValue {
final encoded = base64Encode(utf8.encode('$username:$password'));
return 'Basic $encoded';
}
}
99 changes: 99 additions & 0 deletions gremlin-dart/lib/driver/client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import 'connection.dart';
import 'request_message.dart';
import 'result_set.dart';

class RequestOptions {
final Map<String, dynamic>? bindings;
final String? language;
final int? evaluationTimeout;
final bool? bulkResults;
final String? materializeProperties;

const RequestOptions({
this.bindings,
this.language,
this.evaluationTimeout,
this.bulkResults,
this.materializeProperties,
});
}

class Client {
final Connection _connection;
final ConnectionOptions options;

Client(String url, [ConnectionOptions? options])
: options = options ?? const ConnectionOptions(),
_connection = Connection(url, options);

bool get isOpen => _connection.isOpen;

Future<void> open() => _connection.open();

Future<ResultSet<dynamic>> submit(
String message, {
Map<String, dynamic>? bindings,
RequestOptions? requestOptions,
}) {
return _connection.submit(
_buildRequest(message, bindings: bindings, requestOptions: requestOptions));
}

Stream<dynamic> stream(
String message, {
Map<String, dynamic>? bindings,
RequestOptions? requestOptions,
}) {
return _connection.stream(
_buildRequest(message, bindings: bindings, requestOptions: requestOptions));
}

RequestMessage _buildRequest(
String message, {
Map<String, dynamic>? bindings,
RequestOptions? requestOptions,
}) {
final builder = RequestMessage.build(message)
.addG(options.traversalSource);

if (requestOptions?.language != null) {
builder.addLanguage(requestOptions!.language!);
}
if (requestOptions?.bindings != null) {
builder.addBindings(requestOptions!.bindings!);
}
if (bindings != null) {
builder.addBindings(bindings);
}
if (requestOptions?.materializeProperties != null) {
builder.addMaterializeProperties(requestOptions!.materializeProperties!);
}
if (requestOptions?.evaluationTimeout != null) {
builder.addTimeoutMillis(requestOptions!.evaluationTimeout!);
}
if (requestOptions?.bulkResults != null) {
builder.addBulkResults(requestOptions!.bulkResults!);
}

return builder.create();
}

Future<void> close() => _connection.close();
}
Loading
Loading