-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
306 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ Simple dev example | |
# | ||
"""Development example.""" | ||
from pysui import SuiConfig, handle_result, SyncGqlClient | ||
from pysui import PysuiConfiguration, handle_result, SyncGqlClient | ||
import pysui.sui.sui_pgql.pgql_query as qn | ||
|
@@ -70,7 +70,8 @@ Simple dev example | |
if __name__ == "__main__": | ||
# Initialize synchronous client | ||
client_init = SyncGqlClient(config=SuiConfig.default_config(),write_schema=False) | ||
cfg = PysuiConfiguration(group_name=PysuiConfiguration.SUI_GQL_RPC_GROUP ) | ||
client_init = SyncGqlClient(pysui_config=cfg,write_schema=False) | ||
main(client_init) | ||
------ | ||
|
@@ -83,13 +84,14 @@ copy of a Sui GraphQL RPC schema in use, you can instruct pysui to write a copy | |
.. code-block:: python | ||
:linenos: | ||
from pysui import SuiConfig, SyncGqlClient | ||
from pysui import PysuiConfiguration, SyncGqlClient | ||
def main(): | ||
"""Dump Sui GraphQL Schema.""" | ||
# Initialize synchronous client | ||
client_init = SyncGqlClient(config=SuiConfig.default_config(),write_schema=True) | ||
print(f"Schema dumped to: {client_init.schema_version}.graqhql`") | ||
cfg = PysuiConfiguration(group_name=PysuiConfiguration.SUI_GQL_RPC_GROUP ) | ||
client_init = SyncGqlClient(pysui_config=cfg,write_schema=True) | ||
print(f"Schema dumped to: {client_init.base_schema_version}.graqhql`") | ||
if __name__ == "__main__": | ||
main() | ||
|
@@ -106,13 +108,14 @@ If not provided at construction, it defaults to ``{"headers":None}`` | |
.. code-block:: python | ||
:emphasize-lines: 8,15 | ||
from pysui import SuiConfig, SyncGqlClient | ||
from pysui import PysuiConfiguration, SyncGqlClient | ||
import pysui.sui.sui_pgql.pgql_query as qn | ||
def main(): | ||
"""Set global headers to include in the RPC calls.""" | ||
# Initialize synchronous client with default headers | ||
client = SyncGqlClient(config=SuiConfig.default_config(),default_header={"headers": {"from": "[email protected]"}}) | ||
cfg = PysuiConfiguration(group_name=PysuiConfiguration.SUI_GQL_RPC_GROUP ) | ||
client_init = SyncGqlClient(pysui_config=cfg,default_header={"headers": {"from": "[email protected]"}}) | ||
print(client.client_headers) | ||
# Use different 'from' in headers for this one call | ||
qres = client.execute_query_node( | ||
|
@@ -182,7 +185,7 @@ convert the sting to a ``DocumentNode``, execute the query and either return the | |
# | ||
"""String query example.""" | ||
from pysui import SuiConfig, SyncGqlClient | ||
from pysui import PysuiConfiguration, SyncGqlClient | ||
def main(client: SyncGqlClient): | ||
"""Execute a static string query.""" | ||
|
@@ -202,7 +205,8 @@ convert the sting to a ``DocumentNode``, execute the query and either return the | |
if __name__ == "__main__": | ||
# Initialize synchronous client | ||
client_init = SyncGqlClient(config=SuiConfig.default_config(),write_schema=False) | ||
cfg = PysuiConfiguration(group_name=PysuiConfiguration.SUI_GQL_RPC_GROUP ) | ||
client_init = SyncGqlClient(pysui_config=cfg) | ||
main(client_init) | ||
----------------------- | ||
|
@@ -218,7 +222,7 @@ using ``gql`` functions. | |
"""DocumentNode query example.""" | ||
from gql import gql | ||
from pysui import SuiConfig, SyncGqlClient | ||
from pysui import PysuiConfiguration, SyncGqlClient | ||
def main(client: SyncGqlClient): | ||
"""Execute a DocumentNode as result of `gql` compilation.""" | ||
|
@@ -228,7 +232,8 @@ using ``gql`` functions. | |
if __name__ == "__main__": | ||
# Initialize synchronous client | ||
client_init = SyncGqlClient(config=SuiConfig.default_config(),write_schema=False) | ||
cfg = PysuiConfiguration(group_name=PysuiConfiguration.SUI_GQL_RPC_GROUP ) | ||
client_init = SyncGqlClient(pysui_config=cfg) | ||
main(client_init) | ||
----------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,79 @@ | ||
GraphQL PysuiConfiguration | ||
"""""""""""""""""""""""""""""""" | ||
"""""""""""""""""""""""""" | ||
|
||
PysuiConfiguration is the replacement for the legacy SuiConfig and this new class should be | ||
used with GraphQL clients. | ||
used when creating a new GraphQL clients. This new configuration scheme is also leveraged | ||
by the GraphQL SuiTransaction. | ||
|
||
|
||
General | ||
======= | ||
Up until now, pysui relied on the presence of ``~/.sui`` and it's constituent configuration elements including | ||
``client.yaml``, ``sui.keystore``, and ``sui.aliases`` which were all encapsulated by SuiConfig. While SuiConfig | ||
supported some maniplations (i.e. adding new keys, alias management, etc.) it fell short of a more robust management | ||
strategy. In addition, the code itself did not gracefully age with the advent of Sui GraphQL RPC. Until Mysten | ||
eliminates JSON RPC, SuiConfig may continue to be used with the JSON RPC clients. | ||
|
||
PysuiConfiguration persists its own configuratoin (default to ``~/.pysui``) and offers more flexibility when it | ||
comes to configuration management. Amongst other things: | ||
|
||
#. It does not presume it's configuration is persisted to a fixed location (configurable) | ||
#. It supports programmatic switching between it's primary components (see Anatomy below) | ||
#. It has a smaller code base that, when legacy JSON RPC support is removed, has a smaller memory footprint | ||
#. And more... | ||
|
||
Anatomy of PysuiConfiguration | ||
============================= | ||
The primary data model for PysuiConfiguration is a series of related ``dataclasses`` objects: | ||
|
||
* The root data model is ``PysuiConfigModel`` which is a member of PysuiConfiguration. | ||
It manages one or more... | ||
|
||
* ``ProfileGroup``, or group for short, encapsulates unique environment configurations. | ||
Example configuration may include "sui_json_config" (reserved), "sui_gql_config" (reserved) | ||
or "user" (reserved). New groups may be created by the developer. Its construct includes, | ||
all of which are configurable: | ||
|
||
* One or more ``Profile``, or profile, a named object containing individual urls for communicatinhg to Sui with. | ||
* Associated keys, aliases and addresses | ||
* Identifies an active profile | ||
* Identifies an active address | ||
|
||
PysuiConfiguration | ||
================== | ||
|
||
PysuiConfiguration is the primary object to interact with when managing or using the underlying groups and | ||
profiles. However; it is import to understand the initial setup before using it as part of the GraphQL Clients | ||
and the arguments you can pass to the constructor rely on that understanding. | ||
|
||
First time instantiation | ||
------------------------ | ||
The first time PysuiConfiguration is used it will look for the ``PysuiConfig.json`` file in the | ||
default configuration folder ``~/.pysui`` unless that folder path is overriden with | ||
the argument ``from_cfg_path``. If the configuration file is found it is loaded, otherwise it initializes | ||
a new configuration file with initial groups and their contents. | ||
|
||
If Sui binaries installed | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Three groups will be created and initially populated: | ||
|
||
**sui_json_config** - This group and it's profiles will be populated from the contents of ``~/.sui/sui_config`` from the | ||
files ``client.yaml``, ``sui.keystore`` and ``sui.aliases``. | ||
|
||
**sui_gql_config** - This group and will create four profiles, each one with a ``url`` pointing to Mysten's free | ||
GraphQL nodes. It will also copy the keys, aliases and addresses from the ``sui_json_config`` group. | ||
|
||
**user** - Even though you may create your own groups this group is initially created as a convenience and begins | ||
empty. | ||
|
||
The location of the ``sui`` binary will be captured, if present, enabling Move project compiling. | ||
|
||
If Sui binaries not installed | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
**sui_gql_config** and **user** will be created however; **sui_gql_config** will be populated with a new | ||
active address and keypair (ed25519), an alias of 'Primary', and will make 'testnet' profile active. | ||
|
||
The location of the ``sui`` binary will be captured, if present, enabling Move project compiling. | ||
|
||
PysuiConfiguration Method Summaries | ||
=================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.