Best way to test GraphQL API using Python?

This page summarizes the projects mentioned and recommended in the original post on reddit.com/r/graphql

Our great sponsors
  • Scout APM - Less time debugging, more time building
  • SonarQube - Static code analysis for 29 languages.
  • SaaSHub - Software Alternatives and Reviews
  • Schemathesis

    Run thousands of randomly generated test scenarios based on your API specification and always be sure your API works as expected.

    Hi u/autumn_nite Python has an excellent ecosystem for GraphQL testing. Your first stop for painless GraphQL testing is schemathesis. To test your API with schemathesis, you simply need to start up your GraphQL server, and then run schemathesis like this:

  • hypothesis-graphql

    Generate arbitrary queries matching your GraphQL schema, and use them to verify your backend implementation.

    To create your own test cases, I recommend you use hypothesis-graphql in combination with hypothesis. hypothesis is a property-based testing library. Property-based testing is an approach to testing in which you make assertions about the result of a test given certain conditions and parameters. For example, if you have a mutation that requires a boolean parameter, you can assert that the client will receive an error if it sends a different type. hypothesis-graphql is a GraphQL testing library that knows how to use hypothesis strategies to generate query documents.

  • Scout APM

    Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.

  • hypothesis

    Hypothesis is a powerful, flexible, and easy to use library for property-based testing.

    To create your own test cases, I recommend you use hypothesis-graphql in combination with hypothesis. hypothesis is a property-based testing library. Property-based testing is an approach to testing in which you make assertions about the result of a test given certain conditions and parameters. For example, if you have a mutation that requires a boolean parameter, you can assert that the client will receive an error if it sends a different type. hypothesis-graphql is a GraphQL testing library that knows how to use hypothesis strategies to generate query documents.

  • microservice-apis

    Code repository for my book "Microservice APIs" (https://www.manning.com/books/microservice-apis)

    There's not a whole lot of documentation and tutorials on how to use these tools, but I've written something about them in my upcoming book Microservice APIs. To see a practical example on how to use hypothesis-graphql, check out this file from the book's GitHub repository. For an explanation of the code, check out section 12.5.2 of chapter 12 of the book. Note: that section will go away in the next release of the chapter so make sure you check that specific link. You don't need to buy the book to read the section - Manning allows you to read a few fragments for free every day. To learn to generate hypothesis strategies, check out section 12.3 of chapter 12.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts