Skip to main content

Locust GraphQL client GraphQL. This is a GraphQLLocust equivalent of HttpLocust

Project description

GraphQL Client for Locust

Locust is a python performance test library. Locust supports http client out of the box. This library provides the GraphQL Client for Locust.

This GraphQL Client is based on Prisma's Simple GraphQL Client for Python (https://github.com/prisma/python-graphql-client)

API

class GraphQLClient:
 def execute(self, label, query, variables=None, type ='graphql'):

####Arguments

  • type = Locust Request Type. Default value is 'graphql'
  • label = Locust Name
  • query = GraphQL Query
  • variables = GraphQL Variables. Default value is None

Usage

from locust import HttpLocust, TaskSet, task
from locustgraphqlclient import GraphQLLocust


class UserBehavior(TaskSet):
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled """
        self.login()

    def on_stop(self):
        """ on_stop is called when the TaskSet is stopping """
        self.logout()

    def login(self):
        query = '''
        mutation login($username: String!, $password: String!) {
          login(username: $username, password: $password) {
            access_token
          }
        }'''
        variables = {
            'username': 'gm',
            'password': 'centric8'
        }
        result = self.client.execute("login", query, variables)

        # Inject the Access Token in the Client, so subsequent requests can be made
        self.client.inject_token(result['data']['login']['access_token'])

    def logout(self):
        # Reset the Access Token in the Client, so no subsequent requests can be made
        self.client.inject_token('')

    @task(2)
    def index(self):
        query = '''
                    query products {
                      products {
                        id
                        name
                        image
                      }
                    }'''
        result = self.client.execute("products", query)

    @task(1)
    def profile(self):
        query = '''
                    query me {
                      me {
                        id
                        username
                        firstName
                        lastName                    
                      }
                    }'''
        result = self.client.execute("me", query)


class WebsiteUser(GraphQLLocust):
    task_set = UserBehavior
    min_wait = 5000
    max_wait = 9000

Project details


Download files

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

Source Distribution

locust-graphql-client-0.3.4.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file locust-graphql-client-0.3.4.tar.gz.

File metadata

  • Download URL: locust-graphql-client-0.3.4.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.2

File hashes

Hashes for locust-graphql-client-0.3.4.tar.gz
Algorithm Hash digest
SHA256 b351c3e456b3739e442a34480df98b2de5838682486da4af59c021d1c62fc566
MD5 e6fc68a03b7ec355fe5b70fd2d3517ed
BLAKE2b-256 fdf61c86dc0729e95106624b80cf6b2edb354261e3261386e4d61f6058731470

See more details on using hashes here.

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