有人知道如何对Apollo服务器进行负载测试吗?
class UserBehavior(TaskSet):
def on_start(self):
self.login()
@task
def login(self):
headers = {"content-type": "application/json"}
self.client.post("/", data=json.dumps({
"query": "mutation { login(username:\"9849999983\", password: \"123456\") { token User { id fullName "
"email phoneNumber } } } "
},
headers=headers))
class ApolloSample(HttpLocust):
host = "https://sampleurl.com/api"
min_wait = 20000
max_wait = 50000
task_set = UserBehavior
与此有关的问题是,self.client.post("/")
方法中没有要保留的特定端点。由于Graphql基本上由查询和突变组成。
答案 0 :(得分:1)
以下内容适用于GraphQL查询和变异。不要错过接受标题。
查询
response = self.client.post(
"http://localhost:5424/graphql",
name="GraphQL",
headers={
"Accept": "application/graphql",
"Authorization": "<Authorization-Token>"
},
json={"query": "<Your-GraphQL-Query>" }
)
突变
response = self.client.post(
"http://localhost:5424/graphql",
name="GraphQL",
headers={
"Accept": "application/graphql",
"Authorization": "<Authorization-Token>"
},
json={"query": "<Your-GraphQL-Query>,"
"operationName": "<Operation-Name>,
"variables":"<Input-Variables>" }
)