From 0939b279166967d32188b38efafc60c3875c78b2 Mon Sep 17 00:00:00 2001 From: Andrew Schmadel Date: Tue, 25 Jun 2019 14:07:58 -0400 Subject: [PATCH] expose TypeScript types for apollo-server-testing client (#2871) * add typings for test client * Update CHANGELOG.md * Update CHANGELOG.md --- CHANGELOG.md | 1 + packages/apollo-server-testing/src/createTestClient.ts | 9 +++++++-- packages/apollo-server-testing/src/index.ts | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe69528d857..da3b0c92bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The version headers in this history reflect the versions of Apollo Server itself > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section. - `apollo-server-core`: Avoid duplicate `cacheControl` directives being added via `isDirectiveDefined`. [PR #2762](https://github.com/apollographql/apollo-server/pull/2762) (was reverted in 2.6.1 because previous implementation released in 2.6.0 broke passing in typedefs as a string) +- `apollo-server-testing`: Add TypeScript types for `apollo-server-testing` client. [PR #2871](https://github.com/apollographql/apollo-server/pull/2871) - `apollo-server-plugin-response-cache`: Fix undefined property access attempt which occurred when an incomplete operation was received. [PR #2792](https://github.com/apollographql/apollo-server/pull/2792) [Issue #2745](https://github.com/apollographql/apollo-server/issues/2745) ### v2.6.5 diff --git a/packages/apollo-server-testing/src/createTestClient.ts b/packages/apollo-server-testing/src/createTestClient.ts index 616f7f66f42..d2814ff7ddd 100644 --- a/packages/apollo-server-testing/src/createTestClient.ts +++ b/packages/apollo-server-testing/src/createTestClient.ts @@ -1,4 +1,4 @@ -import { ApolloServerBase } from 'apollo-server-core'; +import { ApolloServerBase, GraphQLResponse } from 'apollo-server-core'; import { print, DocumentNode } from 'graphql'; type StringOrAst = string | DocumentNode; @@ -21,7 +21,12 @@ type Mutation = { operationName?: string; }; -export default (server: ApolloServerBase) => { +export interface ApolloServerTestClient { + query: (query: Query) => Promise; + mutate: (mutation: Mutation) => Promise; +} + +export default (server: ApolloServerBase): ApolloServerTestClient => { const executeOperation = server.executeOperation.bind(server); const test = ({ query, mutation, ...args }: Query | Mutation) => { const operation = query || mutation; diff --git a/packages/apollo-server-testing/src/index.ts b/packages/apollo-server-testing/src/index.ts index acd8c5f2b2b..acb7619a674 100644 --- a/packages/apollo-server-testing/src/index.ts +++ b/packages/apollo-server-testing/src/index.ts @@ -1 +1,4 @@ -export { default as createTestClient } from './createTestClient'; +export { + default as createTestClient, + ApolloServerTestClient, +} from './createTestClient';