Skip to main content
GraphQL

Aliases

QueryParseValidateEasy

Description

Rename fields in response using aliases.

Test Scenario

const query = `
  {
    firstUser: user(id: "1") { name }
    secondUser: user(id: "2") { name }
  }
`;
const { data } = await response.json();
expect(data.firstUser.name).toBeDefined();
expect(data.secondUser.name).toBeDefined();
Endpoint/api/graphql

Testing Tips

  • •Useful for same field with different args
  • •Syntax: alias: fieldName
  • •Prevents field name conflicts
// Playwright API Testing - GraphQL
import { test, expect } from '@playwright/test';
test('GraphQL query', async ({ request }) => {
const response = await request.post('/api/graphql', {
data: {
query: `
query {
users {
id
name
email
}
}
`
}
});
expect(response.ok()).toBeTruthy();
const { data } = await response.json();
expect(data.users).toBeDefined();
});

Challenge ID: graphql-aliases

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/graphql

Press Enter to send