Skip to content

Commit 17719d2

Browse files
committed
proofreading and typo cleanup
1 parent df6e377 commit 17719d2

File tree

4 files changed

+53
-26
lines changed

4 files changed

+53
-26
lines changed

website/pages/docs/testing-approaches.mdx

+27-20
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,37 @@ sidebarTitle: Testing Approaches
55

66
# Testing Approaches
77

8-
Testing is essential for building reliable GraphQL servers. But not every test gives you the same kind of feedback, and not every test belongs at every stage of development. This guide explains the differences between unit tests, integration tests, and end-to-end (E2E) tests, so you can choose the right approach for your project.
8+
Testing is essential for building reliable GraphQL servers. But not every test
9+
gives you the same kind of feedback, and not every test belongs at every stage of development.
10+
This guide explains the differences between unit tests, integration tests, and
11+
end-to-end (E2E) tests, so you can choose the right approach for your project.
912

1013
## Unit tests
1114

12-
Unit tests focus on testing resolver functions in isolation. You run the resolver directly with mocked arguments and context. These tests do not involve your schema or run actual GraphQL queries.
15+
Unit tests focus on testing resolver functions in isolation. You run the resolver directly
16+
with mocked arguments and context. These tests do not involve your schema or run actual
17+
GraphQL queries.
1318

1419
When you write unit tests, you’re checking that the resolver:
20+
1521
- Receives input arguments and context as expected
1622
- Calls the correct business logic
1723
- Handles errors properly
1824
- Returns the correct result
1925

2026
Unit tests are fast and provide tight feedback loops. They're especially useful when:
27+
2128
- Developing new resolvers
2229
- Validating error handling and edge cases
2330
- Refactoring resolver logic and needing immediate verification
2431

25-
However, unit tests have limitations. Because you're mocking inputs and skipping the schema entirely, you won’t catch issues with how your schema connects to your resolver functions. There's also a risk of false positives if your mocks drift from real usage over time.
32+
However, unit tests have limitations. Because you're mocking inputs and skipping the schema
33+
entirely, you won’t catch issues with how your schema connects to your resolver functions.
34+
There's also a risk of false positives if your mocks drift from real usage over time.
2635

2736
### Example: Unit test for a resolver
2837

29-
This test verifies that the resolver produces the expected result, using mocked inputs.
38+
This test verifies that the resolver produces the expected result using mocked inputs.
3039

3140
```javascript
3241
const result = await myResolver(parent, args, context);
@@ -37,21 +46,21 @@ expect(result).toEqual(expectedResult);
3746

3847
Integration tests go a step further by testing resolvers and the schema together.
3948
You can run actual GraphQL queries and verify the end-to-end behavior within your
40-
appliaction's boundaries.
49+
application's boundaries.
4150

42-
You can use the `graphql()` function from the GraphQL pacakage, no HTTP server
51+
You can use the `graphql()` function from the GraphQL package, no HTTP server
4352
needed. With the `graphql()` function, you can test the full flow: query > schema >
4453
resolver > data source (mocked or real).
4554

46-
With integration tests, you are verifiying that:
55+
Integration tests confirm that:
4756

4857
- The schema is correctly wired to resolvers
4958
- Resolvers behave as expected when called through a query
5059
- Data sources return expected results
5160

5261
### When to use integration tests
5362

54-
Integration tests are valuable when:
63+
Use integration tests when:
5564

5665
- You want to test the full operation flow from query to result
5766
- You're testing how resolvers handle variables, fragments, and nested queries
@@ -74,8 +83,7 @@ Trade-offs to consider:
7483
7584
### Example: Integration test with `graphql()`
7685

77-
This test validates that your schema, resolver, and data sources work together
78-
as expected:
86+
This test validates a user query with variables and mocked context.
7987

8088
```js
8189
const query = `
@@ -91,7 +99,7 @@ const result = await graphql({
9199
schema,
92100
source: query,
93101
variableValues: { id: '123' },
94-
contextValue: mockedContext,
102+
contextValue: mockedContext, // mock database, authorization, loaders, etc.
95103
});
96104

97105
expect(result.data).toEqual(expectedData);
@@ -100,7 +108,7 @@ expect(result.data).toEqual(expectedData);
100108
## End-to-End (E2E) tests
101109

102110
E2E tests exercise the entire stack. With your server running and real HTTP
103-
requests in play, you validate not just schema and resolver behvaior, but also:
111+
requests in play, you validate not just schema and resolver behavior, but also:
104112

105113
- HTTP transport
106114
- Middleware such as authentication and logging
@@ -140,27 +148,26 @@ Unit and integration tests are complementary, not competing.
140148
| Setup | Minimal | Schema, mocks, context |
141149
| Best for | Isolated business logic, fast development loops | Verifying resolver wiring, operation flow |
142150

143-
When starting a new project or feature, use unit tests to validate resolver
144-
logic quickly. As your schema grows and you onboard consumers, add integration
145-
tests to confirm that everything works end to end within your application.
151+
Start with unit tests when building new features, then layer in integration tests
152+
to validate schema wiring and catch regressions as your API grows.
146153

147154
## When E2E tests add value
148155

149-
E2E tests are slower and require a full environment setup, but they are essential when:
156+
E2E tests simulate full-stack conditions. Use them when:
157+
150158
- Testing authentication and authorization flows
151159
- Validating infrastructure behavior such as networking and retries
152160
- Coordinating between multiple services and APIs
153161

154-
Think of E2E tests as final rehearsals for your API. They’re not your first
155-
line of defense, but they provide high confidence before deploying to production.
162+
E2E tests are slower and require full setup, so reserve them for critical flows.
156163

157164
## Choosing the right balance
158165

159-
There is no one-size-fits-all approach to testing. Instead, a layered approach
166+
There is no single correct approach to testing. Instead, a layered approach
160167
works best. In general:
161168

162169
- Start with unit tests to move quickly and catch logic errors early
163-
- Add integration tests to ensure scehma and resolver wiring is correct
170+
- Add integration tests to ensure schema and resolver wiring is correct
164171
- Use E2E tests sparingly for high-confidence checks on critical flows
165172

166173
The goal is to build a safety net of tests that gives you fast feedback during

website/pages/docs/testing-best-practices.mdx

+12-5
Original file line numberDiff line numberDiff line change
@@ -64,35 +64,40 @@ maintain.
6464
### Best practices
6565

6666
- Use factories instead of hardcoding:
67+
6768
```ts
6869
function createUser(overrides = {}) {
6970
return { id: '1', name: 'Test User', ...overrides };
7071
}
72+
7173
- Share fixtures:
74+
7275
```ts
7376
export function createTestContext(overrides = {}) {
7477
return {
7578
db: { findUser: jest.fn() },
7679
...overrides,
7780
};
7881
}
79-
```
80-
- Keep test data small and expressive.
82+
83+
- Keep test data small and expressive
8184
- Avoid coupling test data to real database structures
82-
unless explicitly testing integration.
85+
unless explicitly testing integration
8386
84-
## Keep test fast and isolated
87+
## Keep tests fast and isolated
8588
8689
Slow tests kill iteration speed. Fast tests build confidence.
8790
8891
To keep tests lean:
92+
8993
- Use `graphql()` instead of spinning up a server
9094
- Use in-memory or mock data—avoid real databases in most tests
9195
- Group tests by concern: resolver, operation, schema
9296
- Use parallelization (e.g., Jest, Vitest)
9397
- Avoid shared state or global mocks that leak across test files
9498
9599
For large test suites:
100+
96101
- Split tests by service or domain
97102
- Cache expensive steps where possible
98103
@@ -113,15 +118,17 @@ Tests are only useful if they run consistently and early.
113118
114119
## Lint your schema
115120
116-
Testing behavior is only half the battleclean, consistent schemas are
121+
Testing behavior is only the start. Clean, consistent schemas are
117122
easier to maintain and consume.
118123
119124
Use schema linting to enforce:
125+
120126
- Descriptions on public fields and types
121127
- Consistent naming and casing
122128
- Deprecation patterns
123129
- Nullability rules
124130
125131
Tools:
132+
126133
- `graphql-schema-linter`
127134
- `eslint-plugin-graphql`

website/pages/docs/testing-graphql-servers.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ all reliable APIs need testing. The GraphQL compiler and runtime
1414
enforce type correctness, and schema introspection helps clients
1515
understand valid queries.
1616

17-
What GraphQL can't protect you from is:
17+
GraphQL can't protect you from:
1818

1919
- Databases returning incorrect data
2020
- Resolvers throwing unexpected errors

website/pages/docs/testing-operations.mdx

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ optional variables, and context.
3333
5. **Validate the result:** Assert that the `data` is correct and `errors`
3434
is either `undefined` or matches expected failure cases.
3535

36+
## What you can test with operations
37+
38+
Use integration tests to verify:
39+
40+
- Query and mutation flows
41+
- Variable handling and input validation
42+
- Nested field resolution
43+
- Error states and nullability
44+
- Real vs. mocked resolver behavior
45+
46+
These tests help ensure your GraphQL operations behave as expected across a wide
47+
range of scenarios.
48+
3649
## Writing tests
3750

3851
### Queries and mutations

0 commit comments

Comments
 (0)