Skip to content

Commit

Permalink
expose TypeScript types for apollo-server-testing client (#2871)
Browse files Browse the repository at this point in the history
* add typings for test client

* Update CHANGELOG.md

* Update CHANGELOG.md
  • Loading branch information
schmod authored and abernix committed Jun 25, 2019
1 parent 35cd9a1 commit 0939b27
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions packages/apollo-server-testing/src/createTestClient.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,7 +21,12 @@ type Mutation = {
operationName?: string;
};

export default (server: ApolloServerBase) => {
export interface ApolloServerTestClient {
query: (query: Query) => Promise<GraphQLResponse>;
mutate: (mutation: Mutation) => Promise<GraphQLResponse>;
}

export default (server: ApolloServerBase): ApolloServerTestClient => {
const executeOperation = server.executeOperation.bind(server);
const test = ({ query, mutation, ...args }: Query | Mutation) => {
const operation = query || mutation;
Expand Down
5 changes: 4 additions & 1 deletion packages/apollo-server-testing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { default as createTestClient } from './createTestClient';
export {
default as createTestClient,
ApolloServerTestClient,
} from './createTestClient';

0 comments on commit 0939b27

Please sign in to comment.