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 "
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.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.GraphQLToolSpec
class to make a GraphQL query: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")
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.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)
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:graphql_fields = """ # Search for the Transaction with positive Balance stored in the graphql database that has this schema subscription { ... } """
Authorization
header is missing a token. If your GraphQL server requires authentication, you should provide a valid token:headers={ "content-type": "application/json", 'Authorization': 'Bearer your_token_here' }
variables
parameter in the graphql_request
method is an empty dictionary. If your GraphQL query requires any variables, you should provide them here.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.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)
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.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.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.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 ().