diff --git a/docs/goblin/app.mdx b/docs/goblin/app.mdx new file mode 100644 index 0000000000000000000000000000000000000000..84ef55403615bf91635badfbaa37b537b1d7ab3d --- /dev/null +++ b/docs/goblin/app.mdx @@ -0,0 +1,81 @@ +--- +id: app +title: Goblin app +description: 'Using the Goblin app class' +--- + +# Configuring the :py:mod:`Goblin<goblin>` App Object + +The `goblin.app.Goblin` object generally supports the same +configuration options as `aiogremlin.driver.cluster.Cluster`. +Please see the [driver](docs/goblin/driver) for a complete list of +configuration parameters. + + +The `goblin.app.Goblin` object should be created using the +`goblin.app.Goblin.open` classmethod, and configuration can +be passed as keyword arguments, or loaded from a config file. + +```python +import asyncio +from goblin import Goblin + +loop = asyncio.get_event_loop() + +app = loop.run_until_complete(Goblin.open(loop)) +app.config_from_file('config.yml') +``` + +Contents of `config.yml`. + +```python + scheme: 'ws' + hosts: ['localhost'] + port': 8182 + ssl_certfile: '' + ssl_keyfile: '' + ssl_password: '' + username: '' + password: '' + response_timeout: null + max_conns: 4 + min_conns: 1 + max_times_acquired: 16 + max_inflight: 64 + message_serializer: 'goblin.driver.GraphSONMessageSerializer' +``` + +## Special Goblingoblin App Configuration + +`goblin.app.Goblin` supports two additional configuration +keyword parameters: `aliases` and `get_hashable_id`. + +## `aliases` + +`aliases` as stated in the TinkerPop docs: are "a map of key/value pairs that +allow globally bound Graph and TraversalSource objects to be aliased to +different variable names for purposes of the current request". Setting the +aliases on the `goblin.app.Goblin` object provides a default +for this value to be passed on each request. + +## `get_hashable_id` + +`get_hashable_id` is a callable that translates a graph id into a hash +that can be used to map graph elements in the +`goblin.session.Session` element cache. In many cases, +it is not necessary to provide a value for this keyword argument. For example, +TinkerGraph assigns integer IDs that work perfectly for this purpose. However, +other provider implementations, such as DSE, use more complex data structures +to represent element IDs. In this case, the application developer must provide a +hashing function. For example, the following recipe takes an id map and uses +its values to produces a hashable id. + +```python +def get_id_hash(dict): + hashes = map(hash, dict.items()) + id_hash = functools.reduce(operator.xor, hashes, 0) + return id_hash +``` + +Look for provider specific :py:mod:`Goblin<goblin>` libraries in the near +future! diff --git a/sidebars.js b/sidebars.js index e88d20ade1f07b0489c59db4020accef128249cb..2411b8ec6c89db85e7e35d376d75e325f25d8612 100755 --- a/sidebars.js +++ b/sidebars.js @@ -12,7 +12,8 @@ module.exports = { "faq" ], Goblin:[ - "goblin/getting-started", + "goblin/getting-started", + "goblin/app", ], aiogremlin:[ "aiogremlin/getting-started",