Code Monkey home page Code Monkey logo

Comments (5)

leszekhanusz avatar leszekhanusz commented on June 12, 2024 1

your qres variable is an address type and you are selecting a pageInfo field in it, so the request you are trying to build look like:

address(...) {
    cursor: PageInfo {
        ....
    }
}

which does not correspond to the schema.

What you could do instead is something like this:

qres = schema.Query.address(address=for_address)                                                                       
                                                                                                                        
if not after:                                                                                                           
    coin_connection = schema.Address.coinConnection(type="0x2::sui::SUI")                                               
else:                                                                                                                   
    coin_connection = schema.Address.coinConnection(type="0x2::sui::SUI", after=after)                                  
                                                                                                                        
coin_connection.select(                                                                                                 
    cursor=schema.CoinConnection.pageInfo.select(PAGE_CURSOR),                                                          
    gas_objects=schema.CoinConnection.nodes.select(                                                                     
        schema.Coin.balance,                                                                                            
        schema.Coin.asMoveObject.select(                                                                                
            schema.MoveObject.asObject.select(                                                                          
                schema.Object.version,                                                                                  
                schema.Object.digest,                                                                                   
                coin_object_id=schema.Object.location,                                                                  
                owner=schema.Object.owner.select(                                                                       
                    owner_address=schema.Owner.location                                                                 
                ),                                                                                                      
            ),                                                                                                          
            schema.MoveObject.contents.select(                                                                          
                schema.MoveValue.type.select(coin_type=schema.MoveType.repr)                                            
            ),                                                                                                          
        ),                                                                                                              
    ),                                                                                                                  
)                                                                                                                       
                                                                                                                        
qres.select(coin_connection)

from gql.

FrankC01 avatar FrankC01 commented on June 12, 2024 1

Got it! Thanks for the clarification

from gql.

leszekhanusz avatar leszekhanusz commented on June 12, 2024

Please post the error you received and the Graphql schema.

from gql.

FrankC01 avatar FrankC01 commented on June 12, 2024

The error

Traceback (most recent call last):
  File "/Users/fastfrank/.pyenv/versions/3.11.4/lib/python3.11/runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/fastfrank/.pyenv/versions/3.11.4/lib/python3.11/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/Users/fastfrank/.vscode/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/Users/fastfrank/.vscode/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/Users/fastfrank/.vscode/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/Users/fastfrank/.vscode/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/fastfrank/.vscode/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/fastfrank/.vscode/extensions/ms-python.python-2023.20.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/Users/fastfrank/frankc01/pysui-gql/g1.py", line 29, in <module>
    do_gas(client_init)
  File "/Users/fastfrank/frankc01/pysui-gql/g1.py", line 13, in do_gas
    result = client.get_gas2(
             ^^^^^^^^^^^^^^^^
  File "/Users/fastfrank/frankc01/pysui-gql/pgql/gclients.py", line 38, in get_gas2
    sreads.get_gas2(for_address=address, schema=SUI_GRAPHQL_SCHEMA)
  File "/Users/fastfrank/frankc01/pysui-gql/pgql/static_reads.py", line 102, in get_gas2
    qres.select(
  File "/Users/fastfrank/.local/share/virtualenvs/pysui-gql-kXYEURx6/lib/python3.11/site-packages/gql/dsl.py", line 884, in select
    super().select(*fields, **fields_with_alias)
  File "/Users/fastfrank/.local/share/virtualenvs/pysui-gql-kXYEURx6/lib/python3.11/site-packages/gql/dsl.py", line 362, in select
    raise GraphQLError(f"Invalid field for {self!r}: {field!r}")
graphql.error.graphql_error.GraphQLError: Invalid field for <DSLField Query::address>: <DSLField CoinConnection::pageInfo>

The code

def get_gas2(*, for_address: str, schema: DSLSchema, after: str = None) -> DocumentNode:
    """Query to get gas objects owned by address

    :param for_address: The Sui address for the network
    :type for_address: str
    :param schema: The Sui RPC 2.0 schema
    :type schema: DSLSchema
    :param after: Used in paging where caller is controlling node point, optional
    :type after: str, default is None
    :return: Document Query node ready for execution
    :rtype: DocumentNode
    """

    if not after:
        qres = schema.Query.address(address=for_address).select(
            data=schema.Address.coinConnection(type="0x2::sui::SUI")
        )
    else:
        qres = schema.Query.address(address=for_address).select(
            data=schema.Address.coinConnection(type="0x2::sui::SUI", after=after)
        )

    # Query generation
    return dsl_gql(
        PAGE_CURSOR,
        DSLQuery(
            qres.select(
                cursor=schema.CoinConnection.pageInfo.select(PAGE_CURSOR),
                gas_objects=schema.CoinConnection.nodes.select(
                    schema.Coin.balance,
                    schema.Coin.asMoveObject.select(
                        schema.MoveObject.asObject.select(
                            schema.Object.version,
                            schema.Object.digest,
                            coin_object_id=schema.Object.location,
                            owner=schema.Object.owner.select(
                                owner_address=schema.Owner.location
                            ),
                        ),
                        schema.MoveObject.contents.select(
                            schema.MoveValue.type.select(coin_type=schema.MoveType.repr)
                        ),
                    ),
                ),
            )
        ),
    )

Schema attached
schema.graphql.json

from gql.

leszekhanusz avatar leszekhanusz commented on June 12, 2024

In fact, you could even simplify the condition like this:

coin_connection = schema.Address.coinConnection(type="0x2::sui::SUI")                                                   
                                                                                                                        
if after:                                                                                                                
    coin_connection(after=after)

from gql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.