Skip to main content

Framework for automatic GraphQL testing. The framework takes url of your GraphQL endpoint, builds schema and generates http queries for testing.

Project description

gqltst

Framework for automatic GraphQL testing. The framework takes url of your GraphQL endpoint, builds schema and generates http queries for testing.

Example

Installation

pip3 install gqltst

Usage

Prepare your schema

    import gqltst
    schema = gqltst.Schema("https://example.com")

There're already prepared resolvers for Integer, String, Boolean, DateTime and Float, but you can register own resolver for your scalars.

    from gqltst.types import BaseResolver

    class YourResolver(BaseResolver):  
	    def resolve(self, context):  
	        yield "Hello world"

	    def escape(self, value):  
	        return "\"%s\"" % (str(value))  

	    def validate(self, data):  
	        return type(data) == int 

    schema.register_scalar("Myscalar", YourResolver)

Start test with own parameter resolvers

    from gqltst.reslovers import range_resolver, depend_resolver
    from datetime import datetime, timedelta
    from gqltst.types import ValidationResult

    def date_resolver(context):
        now_date = datetime.now()
        for generated_date in [(now_date - timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S"),
                                (now_date - timedelta(days=2)).strftime("%Y-%m-%d %H:%M:%S")]:
            yield generated_date

    args = {
        "environment": {
            "token": range_resolver(["token1", "token2"]),
            "search": {
                "items": {
                    "name": range_resolver(["name1", None, "name3"]),
                    "surname": depend_resolver("$environment_search_items_name", None, ["A", "B"], [None]),
                    "dateFrom": date_resolver,
                    "records": {
                        "first": range_resolver([0]),
                        "step": range_resolver([1]),
                    }
                }
            }
        }
    }

    def test_validator(data, node):
        if data == "Paul":
            return [ValidationResult("It's not our manager", node, data))]
        else:
            return []

    validators = {
        "environment.items.surname": [
            test_validator,
        ],
    }

    schema.test(args=args, validators=validators)

Depensencies

ToDo

  • Stability
  • Better test result view
  • Refactoring
  • Mutations support
  • Specific resolvers

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

gqltst-0.0.7-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page