from graphql.error import GraphQLError # Creating a new GraphQLError object error = GraphQLError("Invalid query syntax", locations=[(3, 5)]) # Printing the error message and location print(error.message) # "Invalid query syntax" print(error.locations) # [(3, 5)]
from graphql.error import GraphQLError # Creating a new GraphQLError object with multiple locations error = GraphQLError("Unknown field 'name'", locations=[(8, 10), (12, 14)]) # Printing the error message and locations print(error.message) # "Unknown field 'name'" print(error.locations) # [(8, 10), (12, 14)]In this example, we are creating a new `GraphQLError` object with a custom error message and multiple locations where the error occurred in the query. Overall, the `GraphQLError` class is a useful tool for handling errors in GraphQL queries in Python.