Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rohitghatol/locust-graphql-client
GraphQL Client for Locust
https://github.com/rohitghatol/locust-graphql-client
graphql graphql-client locust performace-testing python
Last synced: about 2 months ago
JSON representation
GraphQL Client for Locust
- Host: GitHub
- URL: https://github.com/rohitghatol/locust-graphql-client
- Owner: rohitghatol
- License: apache-2.0
- Created: 2019-08-26T01:21:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-21T22:14:31.000Z (almost 2 years ago)
- Last Synced: 2024-10-31T19:51:29.513Z (about 2 months ago)
- Topics: graphql, graphql-client, locust, performace-testing, python
- Language: Python
- Size: 11.7 KB
- Stars: 8
- Watchers: 2
- Forks: 15
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```python
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
```python
from locust import HttpLocust, TaskSet, task
from locustgraphqlclient import GraphQLLocustclass 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```