Registry / testing / playwright-graphql

playwright-graphql

JSON →
library2.2.1jsnpmunverified

Library integrating GraphQL testing with Playwright and TypeScript. Version 2.2.1 provides auto-generated, type-safe GraphQL API clients with autocomplete, schema/operation generation, and optional coverage reporting. Key differentiators: built-in CLI for codegen, fixtures for Playwright test context, raw response access, negative testing support, and GraphQL coverage reports. Alternatives like Apollo Client or graphql-request lack Playwright-specific integration and testing utilities.

npm install playwright-graphql
INSTALL
IMPORT
SIG · PLAYWRIGHT-GRAPHQL
P
playwright-graphql
testingjavascriptv2.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getClient
import { getClient } from 'playwright-graphql'
import getClient from 'playwright-graphql'
Named export, not default. ESM-only since v2.
GqlAPI
import { GqlAPI } from 'playwright-graphql/generated/graphql'
import { GqlAPI } from 'playwright-graphql'
GqlAPI type is generated in the gql/graphql.ts file, not from the main package.
getClient (CJS)
const { getClient } = require('playwright-graphql')
const getClient = require('playwright-graphql')
CommonJS require destructures named export.

Shows how to set up a GraphQL client fixture in Playwright test and use generated query/mutation operations.

import { test, expect } from '@playwright/test'; import { getClient } from 'playwright-graphql'; import { GqlAPI } from '../gql/graphql'; test.describe('GraphQL API tests', () => { let api: GqlAPI; test.beforeAll(async ({ playwright }) => { const apiContext = await playwright.request.newContext({ baseURL: process.env.API_URL ?? 'http://localhost:4000', }); api = getClient(apiContext, { endpoint: '/graphql', headers: { 'x-api-key': process.env.API_KEY ?? '' }, }); }); test('should fetch users', async () => { const response = await api.query.GetUsers(); expect(response.status()).toBe(200); const body = await response.json(); expect(body.data.users).toBeDefined(); }); test('should create user', async () => { const response = await api.mutation.CreateUser({ variables: { name: 'John', email: 'john@example.com' }, }); expect(response.status()).toBe(200); const body = await response.json(); expect(body.data.createUser.id).toBeDefined(); }); });
Debug
Known issues
breakingVersion 2.0 moved getClient export to named import (was default import).
fix
Change import from `import getClient from ...` to `import { getClient } from ...`
affects: >=2.0.0 <2.0.0
deprecatedRaw response option uses `raw: true` which may change in future.
fix
Use `getClient(apiContext, { raw: true })` but expect future API adjustments.
affects: >=2.2.0
gotchaGqlAPI type is only available after running codegen CLI command.
fix
Run `playwright-graphql --schema schema.gql` before trying to import generated types.
affects: >=2.0.0
gotchaCLI requires either --schema or --url, not both. Using --url with existing schema will overwrite.
fix
Provide only one source. Use --schema for local file, --url for remote endpoint.
affects: >=2.0.0
gotchaPeer dependency @playwright/test must be >= 1.44.x, incompatible with older versions.
fix
Update @playwright/test to version 1.44 or higher.
affects: >=2.0.0
Errors
Common errors & fixes
ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './generated/graphql' is not defined by "exports"
Attempting to import from the generated file before running codegen.
fix
Run the CLI command first: npx playwright-graphql --schema schema.gql
TypeError: (0 , playwright_graphql_1.getClient) is not a function
Using default import instead of named import for getClient in v2.
fix
Change to: import { getClient } from 'playwright-graphql'
Cannot find module '@playwright/test' or its corresponding type declarations
Missing peer dependency @playwright/test.
fix
Install: npm install -D @playwright/test@^1.44
Upgrade
Version history
2.2.1latest on npm
Audit
Dependencies
@playwright/testrequiredPeer dependency required for Playwright integration
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
playwright-graphql — npm install playwright-graphql · libregistry