0.0.12 • Published 4 years ago

@os-utils/graphql-test-client v0.0.12

Weekly downloads
12
License
MIT
Repository
-
Last release
4 years ago

@os-utils/graphql-test-client

The wrapper of the superagent to make GraphQL queries in tests.

Unlike apollo-boost and apollo-client, superagent saves cookies in the Node.js environment.

Examples

Base request

import TestClient from '@os-utils/graphql-test-client'

// Example of mutation
const signInMutation = `
  mutation SignInMutation($input: SignInInput!) {
    signIn(input: $input) {
      ok
    }
  }
`

it('Should make a request successfully', async () => {
  // Example of input data
  const input = {
    email: 'name@domain.com',
    password: 'password',
  }

  // Create an instance of TestClient ans pass the GraphQL url
  const client = new TestClient({
    url: 'http://localhost:4000/graphql',
  })

  // Make a GraphQL request and pass the variables
  const res = await client.query({
    query: signInMutation,
    variables: { input },
  })

  expect(res.body.errors).toBeUndefined()
  expect(res.body.data).toBeDefined()
})

Request with cookies

import TestClient from '@os-utils/graphql-test-client'

const signInMutation = `
  mutation SignInMutation($input: SignInInput!) {
    signIn(input: $input) {
      ok
    }
  }
`

const profileQuery = `
  query profileQuery {
    profile {
      email
      firstName
      lastName
    }
  }
`

it('Should sign in successfully', async () => {
  const input = {
    email: 'name@domain.com',
    password: 'password',
  }

  const client = new TestClient({
    url: 'http://localhost:4000/graphql',
    saveCookies: true,
  })

  await client.query({
    query: signInMutation,
    variables: { input },
  })

  const res = await client.query({
    query: profileQuery,
  })
  
  expect(res.body.errors).toBeUndefined()
  expect(res.body.data).toBeDefined()
})
0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago