GraphQL
Schema Introspection
QueryParseValidateMedium
What you will learn
- Introspection is a powerful debug tool AND an information-disclosure vector โ disable on public prod APIs
- Test that __schema and __type queries are either allowed (dev) or return 403 (prod) โ no half-measures
- Field-level docstrings help clients, but NEVER include internal business logic, schemas, or secrets in descriptions
Description
Query the schema to discover types and fields.
Test Scenario
const query = `
{
__schema {
queryType { name }
mutationType { name }
types { name kind }
}
}
`;Endpoint
/api/graphqlTesting Tips
- โขUse __schema and __type queries
- โขDiscover available queries/mutations
- โขCheck field types and descriptions
// Playwright API Testing - GraphQLimport { test, expect } from '@playwright/test';test('GraphQL query', async ({ request }) => {const response = await request.post('/api/graphql', {data: {query: `query {users {idname}}`}});expect(response.ok()).toBeTruthy();const { data } = await response.json();expect(data.users).toBeDefined();});
Challenge ID: graphql-introspection
2 frameworks available
API Playground
Send requests and inspect responses
Endpoint: /api/graphql
Press Enter to send