from prefect.utilities.graphql import GraphQLResult result = GraphQLResult({"data": {"foo": "bar"}}) print(result.data["foo"]) # Output: "bar"
import requests from prefect.utilities.graphql import GraphQLResult query = """ query { users { id name } } """ response = requests.post("https://mygraphqlserver.com/graphql", json={"query": query}) result = GraphQLResult(response.json()) users = result.data["users"] for user in users: print(user["id"], user["name"])This code sends a GraphQL query to a server and receives a response as JSON. It then creates a GraphQLResult object from the JSON response and accesses the "users" field, which is an array of user objects. It prints the ID and name of each user in the array. Package library: prefect.