Find answers from the community

Updated 6 months ago

how to add ```graphql_fields = """subscription { Solana { InstructionBalanceUpdates(

@kapa.ai how to add
Plain Text
graphql_fields = """subscription {
  Solana {
    InstructionBalanceUpdates(limit: {count: 10}) {
      Transaction {
        Index
        FeePayer
        Fee
        Signature
        Result {
          Success
          ErrorMessage
        }
      }
      Instruction {
        InternalSeqNumber
        Index
        CallPath
        Program {
          Address
          Name
          Parsed
        }
      }
      Block {
        Time
        Hash
        Height
      }
      BalanceUpdate {
        Account {
          Address
        }
        Amount
        Currency {
          Decimals
          CollectionAddress
          Name
          Key
          IsMutable
          Symbol
        }
      }
    }
  }
}
"""

suffix = "Search for the Transaction with positive Balance stored in the graphql database that has this schema "
within llamaindex graphql
k
a
12 comments
Please stand by @andysingal as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To add the graphql_fields within LlamaIndex GraphQL, you would typically use the GraphQLReader or GraphQLToolSpec classes. However, the provided knowledge sources do not contain specific examples or instructions on how to add a subscription query like the one you provided.

The GraphQLReader class is used to read and process GraphQL schemas, and the GraphQLToolSpec class is used to make GraphQL queries against a server. However, the specifics of how to use these classes to add a subscription query to a GraphQL schema are not provided in the knowledge sources.

Here is a general example of how you might use the GraphQLToolSpec class to make a GraphQL query:

Plain Text
from llama_index.tools.graphql.base import GraphQLToolSpec

tool = GraphQLToolSpec(url="your_graphql_server_url")
response = tool.graphql_request(query=graphql_fields, variables={}, operation_name="YourOperationName")


In this example, graphql_fields would be your subscription query, and url would be the URL of your GraphQL server. The variables and operation_name parameters would depend on the specifics of your query and server.

Please note that this is a general example and might not work for your specific use case without modification. For more detailed instructions, you should refer to the LlamaIndex GraphQL documentation () and the LlamaIndex Tools documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai any issues with the code:
Plain Text
from llama_index.tools.graphql import GraphQLToolSpec
from llama_index.agent.openai import OpenAIAgent

tool_spec = GraphQLToolSpec(
    url="https://streaming.bitquery.io/eap/",
    headers={
        "content-type": "application/json",
        'Authorization': 'Bearer'
    },
)

# agent = OpenAIAgent.from_tools(tool_spec.to_tool_list())

# agent.chat(
#     "get the id, model, name and type of the Ships from the graphql endpoint"
# )

graphql_fields = """subscription {
  Solana {
    InstructionBalanceUpdates(limit: {count: 10}) {
      Transaction {
        Index
        FeePayer
        Fee
        Signature
        Result {
          Success
          ErrorMessage
        }
      }
      Instruction {
        InternalSeqNumber
        Index
        CallPath
        Program {
          Address
          Name
          Parsed
        }
      }
      Block {
        Time
        Hash
        Height
      }
      BalanceUpdate {
        Account {
          Address
        }
        Amount
        Currency {
          Decimals
          CollectionAddress
          Name
          Key
          IsMutable
          Symbol
        }
      }
    }
  }
}
"""

suffix = "Search for the Transaction with positive Balance stored in the graphql database that has this schema "

response = tool_spec.graphql_request(query=graphql_fields + suffix, variables={}, operation_name="YourOperationName")

print(response)
Let me check the knowledge base for you. One moment! :books:
----------------------
Based on the provided knowledge sources, there are a few potential issues with your code:

  1. The suffix variable is a string that seems to be a description or instruction, not a part of a GraphQL query. Adding it to the graphql_fields variable might cause a syntax error in the GraphQL query. If you want to add a comment to your GraphQL query, you should use the # symbol:
Plain Text
graphql_fields = """
# Search for the Transaction with positive Balance stored in the graphql database that has this schema
subscription {
  ...
}
"""


  1. The Authorization header is missing a token. If your GraphQL server requires authentication, you should provide a valid token:
Plain Text
headers={
    "content-type": "application/json",
    'Authorization': 'Bearer your_token_here'
}


  1. The variables parameter in the graphql_request method is an empty dictionary. If your GraphQL query requires any variables, you should provide them here.
  1. The operation_name parameter in the graphql_request method is a placeholder string. If your GraphQL server requires an operation name, you should provide the correct one here.
Please note that these are potential issues based on the provided code and knowledge sources. The actual issues might be different depending on the specifics of your GraphQL server and query. For more detailed instructions, you should refer to the LlamaIndex GraphQL documentation () and the LlamaIndex Tools documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
i tried the above but get empty response @kapa.ai
@WhiteFang_Jr @Logan M any ways to solve this issue? Added a ticket: https://github.com/run-llama/llama_index/issues/14573
@kapa.ai what is shopify-schema.txt in
Plain Text
import json
from graphql import parse

with open("data/shopify_graphql.txt", "r") as f:
    txt = f.read()

ast = parse(txt)

query_root_node = next(
    (
        defn
        for defn in ast.definitions
        if defn.kind == "object_type_definition" and defn.name.value == "QueryRoot"
    )
)
query_roots = [field.name.value for field in query_root_node.fields]
print(query_roots)
Let me check the knowledge base for you. One moment! :books:
----------------------
The shopify_graphql.txt file in the provided code is a text file that contains the GraphQL schema for a Shopify store. This schema defines the types of data that can be queried from the Shopify store's GraphQL API.

In the provided code, the shopify_graphql.txt file is opened and its contents are read into the txt variable. The parse function from the graphql library is then used to parse this text into an Abstract Syntax Tree (AST), which is a tree representation of the structure of the GraphQL schema.

The query_root_node is then extracted from the AST. This is the root node for all queries that can be made against the Shopify store's GraphQL API. The names of all fields in the query_root_node are then printed out. These field names represent the top-level types of data that can be queried from the Shopify store's GraphQL API.

Please note that the actual contents and structure of the shopify_graphql.txt file would depend on the specifics of the Shopify store's GraphQL API. For more information on GraphQL schemas, you can refer to the GraphQL documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@Logan M can you please help with above issue… if you have a copy of .txt used in the Shopify example that would also be great start for me
Add a reply
Sign up and join the conversation on Discord