蝗虫graphql客户端graphql。这是相当于httplocast的graphqlocast

locust-graphql-client的Python项目详细描述


蝗虫graphql客户端

蝗虫是一个python性能测试库。蝗虫支持现成的http客户端。 这个库为蝗虫提供了graphql客户端。

这个graphql客户端基于prisma的简单的python graphql客户端(https://github.com/prisma/python-graphql-client

API

classGraphQLClient:defexecute(self,label,query,variables=None,type='graphql'):

####参数

  • type=蝗虫请求类型。默认值为“graphql”
  • label=蝗虫名称
  • query=graphql查询
  • variables=graphql变量。默认值为无

用法

fromlocustimportHttpLocust,TaskSet,taskfromlocustgraphqlclientimportGraphQLLocustclassUserBehavior(TaskSet):defon_start(self):""" on_start is called when a Locust start before any task is scheduled """self.login()defon_stop(self):""" on_stop is called when the TaskSet is stopping """self.logout()deflogin(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 madeself.client.inject_token(result['data']['login']['access_token'])deflogout(self):# Reset the Access Token in the Client, so no subsequent requests can be madeself.client.inject_token('')@task(2)defindex(self):query='''                    query products {                      products {                        id                        name                        image                      }                    }'''result=self.client.execute("products",query)@task(1)defprofile(self):query='''                    query me {                      me {                        id                        username                        firstName                        lastName                                          }                    }'''result=self.client.execute("me",query)classWebsiteUser(GraphQLLocust):task_set=UserBehaviormin_wait=5000max_wait=9000

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将Scanner对象作为构造函数参数传递给UserInterface类   spring未能启动bean“subtocolWebSocketHandler”;嵌套的例外是java。lang.IllegalArgumentException:没有处理程序   Java EE应用程序中后台服务的多线程Java线程(设置守护进程和优先级)?   java Pull to refresh返回列表的第一个位置   无法将comparator类转换为java。可比的   java将json从servlet传递到dojo   JavaHibernate:将子类实例转换为超类实例   java警告调用servlet类时非法反射访问   java静态变量值   java@Entity和@embeddeble之间有什么区别   java将作业配置导入公共作业配置类(注释配置)   sql公共表表达式(以values语句开头)在java中给出错误   java在ImageJ中使用ImageProcessor   java PostgreSQL executeBatch()会随着时间的推移而变慢   java在安卓中以表格形式排列sqllite表数据?   java中SVG的swing定制呈现   java删除与另一个实体映射的实体   java何时/如何添加ListView适配器,使用back按钮恢复它?(片段)   java为什么IBinder和Binder之间的类型转换不是非法的?   java在方法参数列表中使用ArrayList或List