-
hypothesis-graphql
Generate arbitrary queries matching your GraphQL schema, and use them to verify your backend implementation.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
microservice-apis
Code repository for my book "Microservice APIs" (https://www.manning.com/books/microservice-apis)
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:
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.
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.
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.