Python - parse graphql, add something, then back to the query string

Viewed 1768

I'm trying to use python to parse a graphql query, alter it, and turn it back into a string query that I can pass to the graphql server.

Specifically, I'm trying to ensure that a query will always have the pageInfo paging information, so if I'm executing a query, I will always be able to automatically page through the results, even if a user might forget that stanza in their actual query.

It seems surprisingly difficult to parse a graphql query into something useful, and then be able to go from the parsed data representation back to the query string. Is there a library that google isn't able to turn up for me?

Thanks so much for any help!

1 Answers

The core library includes a parse function for parsing strings into AST and a print_ast function for converting the AST back to a string.

Related