Search code examples
pythongraphqlethereumthegraph

Python GraphQL Client - Unexpected punctuator when passing variables


Code:

contract="0xdAC17F958D2ee523a2206206994597C13D831ec7"

query = """
($contract: Int!) {
 token(id:$contract){
   name
   symbol
   decimals
   derivedETH
   tradeVolumeUSD
   totalLiquidity
 }
}
"""

variables = {
    "contract": contract
}

data = client.execute(query=query, variables=variables)

Error:

{'errors': [{'locations': [{'column': 1, 'line': 2}], 'message': 'Unexpected `([Punctuator]`\nExpected `{`, `query`, `mutation`, `subscription` or `fragment`'}]}

I've tried reformatting a number of ways and I cannot get this error to go away! Help!


Solution

  • Your GraphQL query must start with a query:

    query($someVar: String!) {
      someQuery(someArg: $someVar) {
         ...
      }
    }