
Security News
AI Agent Submits PR to Matplotlib, Publishes Angry Blog Post After Rejection
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.
apollo-server-integration-testing
Advanced tools
This package exports an utility function for writing apollo-server integration tests:
import { createTestClient } from 'apollo-server-integration-testing';
This function takes in an apollo server instance and returns a function that you can use to run operations against your schema, and assert on the results.
Example usage:
import { createTestClient } from 'apollo-server-integration-testing';
import { createApolloServer } from './myServerCreationCode';
const apolloServer = await createApolloServer();
const query = createTestClient({
apolloServer
});
const result = await query(`{ currentUser { id } }`);
expect(result).toEqual({
data: {
currentUser: {
id: '1'
}
}
});
This allows you to test all the logic of your apollo server, including any logic inside of the context option that you can pass to the ApolloServer constructor.
Request objectcreateTestClient automatically mocks the Request object that will be passed to the context option of your ApolloServer constructor, so testing works out of the box.
You can also extend the mocked Request object with additional keys by passing an extendMockRequest field to createTestClient:
const query = createTestClient({
apolloServer,
extendMockRequest: {
headers: {
cookie: 'csrf=blablabla',
referer: ''
}
}
});
This is useful when your apollo server context option is a callback that operates on the passed in req key, and you want to inject data into that req object.
As mentioned above, if you don't pass an extendMockRequest to createTestClient, we provide a default request mock object for you. See https://github.com/howardabrams/node-mocks-http#createrequest for all the default values that are included in that mock.
apollo-server-testing?You can't really write real integration tests with apollo-server-testing, because it doesn't support servers which rely on the context option being a function that uses the req object (see this issue for more information).
Real apollo-servers support this behavior, but the test client created with apollo-server-testing does not. For example:
import { createTestClient } from 'apollo-server-testing';
it('will not work', () => {
const { query } = createTestClient(
new ApolloServer({
schema,
context: ({ req }) => {
return doSomethingWithReq(req); // this won't work because `req` is `undefined`.
}
})
);
// Any middleware or resolver code that depends on `context` will not work when this runs, because
// the `context` function does *not* get passed `req` as expected.
const result = await query(
`{ currentUser { id } }`
)
});
The official integration example code from Apollo solves this by instantiating an ApolloServer inside the test and mocking the context value by hand. But I don't consider this a real integration test, since you're not using the same instantiation code that your production code uses.
If you want to help out, here's a TODO list:
This package should work for consumers using apollo-server or apollo-server-express. We don't plan on supporting any other node server integrations at this time.
FAQs
Test helper for writing apollo-server integration tests
The npm package apollo-server-integration-testing receives a total of 1,163 weekly downloads. As such, apollo-server-integration-testing popularity was classified as popular.
We found that apollo-server-integration-testing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.

Security News
HashiCorp disclosed a high-severity RCE in next-mdx-remote affecting versions 4.3.0 to 5.x when compiling untrusted MDX on the server.

Security News
Security researchers report widespread abuse of OpenClaw skills to deliver info-stealing malware, exposing a new supply chain risk as agent ecosystems scale.