GithubHelp home page GithubHelp logo

rohitghatol / locust-graphql-client Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 15.0 12 KB

GraphQL Client for Locust

License: Apache License 2.0

Python 100.00%
graphql graphql-client locust python performace-testing

locust-graphql-client's Introduction

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

locust-graphql-client's People

Contributors

danielebra avatar field-testing avatar rohitghatol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

locust-graphql-client's Issues

Support passthrough HTTP Headers

We have a firewall which requires a header value to bypass, and I cannot send a header with my GQL request to do this.

Expected:

self.client.execute("myGQLQuery", query, headers={"x-firewall-bypass": "true"})

Result:

/ERROR/locust.core: execute() got an unexpected keyword argument 'headers'

Rename Locust to User due to Breaking Change

I get this error message:

ImportError: The Locust class has been renamed to User in version 1.0. For more info see: https://docs.locust.io/en/latest/changelog.html#changelog-1-0

And it's coming from here

I believe that it's just a simple renaming of the class or at the very least the setup.py should be version locked to a version of locust that this lib supports via install_requires.

https://docs.locust.io/en/latest/changelog.html#changelog-1-0

Let me know for anything missed!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.