Performance test for graphQL API

前端 未结 7 1435
北恋
北恋 2021-02-04 20:07

Today I\'m doing my API automation testing and performance testing with Jmeter when the server is a REST API.

Now the development changed to graphQL API, and I have two

相关标签:
7条回答
  • 2021-02-04 20:26

    I use Apollo to build the GraphQL server, and use JMeter to query the GraphQL API as below.

    1. Set up HTTP Request

    2. Set up HTTP Headers

    Depending on your application, you might also need to set up HTTP header Authorization for JWT web tokens, such as:

    Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxx
    

    3. Set up HTTP Cookie if needed for your app

    4. Run the test

    0 讨论(0)
  • 2021-02-04 20:40

    I am testing our GraphQL Implementation, you will need:

    • Thread Group
    • HTTP Header Manager: You need to add as Content-Type: Application/json https://i.stack.imgur.com/syXqK.png
    • HTTP Request: use GET and add in the Body Data your query https://i.stack.imgur.com/MpxAb.png
    • Response Assertion: You want to count as correct requests only responses without errors https://i.stack.imgur.com/eXWGs.png
    • A Listener: https://i.stack.imgur.com/VOVLo.png
    0 讨论(0)
  • 2021-02-04 20:42

    You can try using easygraphql-load-tester

    How it works:

    easygraphql-load-tester is a node library created to make load testing on GraphQL based on the schema; it'll create a bunch of queries, that are going to be the ones used to test your server.

    Examples:

    • Artillery.io
    • K6

    Result:

    Using this package, it was possible to me, to identify a bad implementation using dataloaders on the server.

    Results without dataloaders

    All virtual users finished
    Summary report @ 10:07:55(-0500) 2018-11-23
      Scenarios launched:  5
      Scenarios completed: 5
      Requests completed:  295
      RPS sent: 36.88
      Request latency:
        min: 1.6
        max: 470.9
        median: 32.9
        p95: 233.2
        p99: 410.8
      Scenario counts:
        GraphQL Query load test: 5 (100%)
      Codes:
        200: 295
    

    Results with dataloaders

    All virtual users finished
    Summary report @ 10:09:09(-0500) 2018-11-23
      Scenarios launched:  5
      Scenarios completed: 5
      Requests completed:  295
      RPS sent: 65.85
      Request latency:
        min: 1.5
        max: 71.9
        median: 3.3
        p95: 19.4
        p99: 36.2
      Scenario counts:
        GraphQL Query load test: 5 (100%)
      Codes:
        200: 295
    
    0 讨论(0)
  • 2021-02-04 20:42

    I have recently tried API testing with GraphQl with both GET and POST request in Jmeter

    Make sure its POST request for both Query and Mutation

    Example Your Graph Ql query

    {
      storeConfig{
        default_title
        copyright
      }
    }
    

    For Jmeter it would be like this

    {
        "query":"{ storeConfig { default_title copyright } }"
    }
    

    Step up HTTP Request

    In place of the localhost, your domain name will come. Make sure you don't add https

    Example:- https://mydomainname.com

    In Jmeter :- mydomainname.com

    Setup HTTP Header Manager

    For requesting Mutation in Jmeter

    Example mutation in Graphql

     mutation {
          generateCustomerToken(
              email: "rd@mailinator.com"
              password: "1234567"
          ) {
              token
       }
    }
    

    In Jemeter mutation will be like this

    {
        "query":"mutation { generateCustomerToken( email: \"rd@mailinator.com\" password: \"1234567\" ) { token } }"
    }
    

    Replace double quotes with (\") as shown in above query

    0 讨论(0)
  • 2021-02-04 20:45

    Disclaimer: I work for LoadImpact; the company behind k6.

    If you are willing to consider an alternative, I've recently written a blog post about this topic: Load testing GraphQL with k6.

    This is how a k6 example looks like:

    let accessToken = "YOUR_GITHUB_ACCESS_TOKEN";
    
    let query = `
     query FindFirstIssue {
       repository(owner:"loadimpact", name:"k6") {
         issues(first:1) {
           edges {
             node {
               id
               number
               title
             }
           }
         }
       }
     }`;
    
    let headers = {
     'Authorization': `Bearer ${accessToken}`,
     "Content-Type": "application/json"
    };
    
    let res = http.post("https://api.github.com/graphql",
     JSON.stringify({ query: query }),
     {headers: headers}
    );
    
    0 讨论(0)
  • 2021-02-04 20:45

    Looking into Serving over HTTP section of the GraphQL documentation

    When receiving an HTTP GET request, the GraphQL query should be specified in the "query" query string.

    So you can just append your GraphQL query to your request URL.

    With regards to "best practices" - you should follow "normal" recommendations for web applications and HTTP APIs testing, for example check out REST API Testing - How to Do it Right article.

    0 讨论(0)
提交回复
热议问题