1.1.1 • Published 3 years ago

gql-load-tester v1.1.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

Load tester to simulate graphql based api (currently only works with Apollo graphql queries). Scenarios can be used to simulate user behaviours.

#Installation

  npm i gql-load-tester
  yarn add gql-load-tester

using ts-node is advised (https://www.npmjs.com/package/ts-node).

 npm install -g typescript
 npm install -g ts-node

Its also possible to run it with node js (not fully tested).

#Usage

  • Create a .ts file.
  • import and run the LoadTester function and your queries (assuming they are written in typescript).
  • run ts-node <your .ts file>.

(the process should be similar when using node and using a .js file)

#API

interface ILoadTester {
    apolloConfig: ApolloConfig, // Check apollo client config https://www.npmjs.com/package/@apollo/client
    duration?: number; // in seconds, specified how long the test should run.
                       // If a scenario completes before the duration ends, the scenario will be repeated
                       // Not specifying duration will run the users only once
    scenario: Scenario;
    parallelUsers: number; // number of users running a Scenario at any point in time
}

interface Scenario {
    initialPollingQueries?: PollingQuery[]
    steps: Step[];
}

interface Step { // Steps for the scenario, each step is carried out sequentially
    query?: Query,
    mutation?: Mutation,
    pollingQuery?: PollingQuery[], // polling queries can also be started during a step
    name: string;
}

interface PollingQuery extends Query{
    timer: number // milliseconds
}

#Example

import {gql} from '@apollo/client';

const APP_VERSION_QUERY = gql` // example query
  query version($os: String) {
    version(os: $os) {
      version
    }
  }
`;

export const PROFILE_QUERY = gql`  // example query
  query profile {
     name
  }
`;

LoadTester({
        apolloConfig : {
          uri: '<Your Server Url>',
          headers: { authorization: `Bearer XXXX`}
        },
        parallelUsers: 20,
        duration: 20,
        scenario:{
          steps:[{ 
              name: 'Profile',
              query: {
                 query: PROFILE_QUERY
              }
          },
          {
             name: 'AppVersion Query', 
             query: {
                   query: APP_VERSION_QUERY, variables: {os: 'ios'}
             }
          }]
       }
 })
1.1.1

3 years ago

1.0.19

3 years ago

1.1.0

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago