Search code examples
pythongraphqlweb-api-testinggraphene-pythongraphql-java

How to specify (import?) scheme in GraphQL in python (graphene?)?


shame to ask, but we have GraphQL Server on Java (https://github.com/graphql-java/graphql-spring-boot), where we specified type.graphqls scheme for our service.
On client side we have JS code based on Apollo Client library. And it does not need acess to this types file.
But days are come and I need to write some API tests. Most people in our team speaks Python very well, so I decided to make test workbench on python, but I cant't find any library that let me write queries schema-free or import my types.graphqls scheme.
How can I write tests on python for custom GraphQL server thogh?
Thanks!


Solution

  • Finally I found a gist with simple GraphQL client based on requests library:

    import requests
    
    def run_query(query, variables):
        request = requests.post('https://dev.darkdata.finance:9000/graphql',
                            json={'query': query, 'variables': variables})
    
        if request.status_code == 200:
            return request.json()
        else:
            raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query))
    

    You can use it to test simple queries if you want. Source: https://gist.github.com/gbaman/b3137e18c739e0cf98539bf4ec4366ad