4

Does anyone know how to load test the Apollo server?

 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

The problem with this is that, there is no particular endpoint to keep in the self.client.post("/") method. Since Graphql basically consist of Queries and Mutations.

Sujin Shrestha
  • 1,203
  • 2
  • 13
  • 23

2 Answers2

4

Following would work for GraphQL queries & mutation. Don't miss Accept headers.

Queries

response = self.client.post(
            "http://localhost:5424/graphql",
            name="GraphQL",
            headers={
                "Accept": "application/graphql",
                "Authorization": "<Authorization-Token>"
            },
            json={"query": "<Your-GraphQL-Query>" }
        )

Mutation

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>" }
        )
localhost
  • 228
  • 1
  • 11
0

response = self.client.post(
            "http://localhost:5424/graphql",
            name="GraphQL",
            headers={
                "Accept": "application/graphql",
                "Authorization": "<Authorization-Token>"
            },
            json={"query": "<Your-GraphQL-Query>" }
        )
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 26 '21 at 10:42