Skip to content

Commit

Permalink
[apollo-server-testing] add complete typing for ...rest args
Browse files Browse the repository at this point in the history
  • Loading branch information
feinoujc committed Apr 13, 2019
1 parent 57c0056 commit 81b9aa9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/apollo-server-testing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

### vNEXT

* Add variables prop to Query and Mutation types. Fixes #2172

* `apollo-server-testing`: Added createTestClient function
9 changes: 8 additions & 1 deletion packages/apollo-server-testing/src/createTestClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ApolloServerBase } from 'apollo-server-core';
import { print, DocumentNode } from 'graphql';

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

type StringOrAst = string | DocumentNode;

// A query must not come with a mutation (and vice versa).
Expand All @@ -9,7 +11,12 @@ type Mutation = { mutation: StringOrAst; query?: undefined };

export default (server: ApolloServerBase) => {
const executeOperation = server.executeOperation.bind(server);
const test = ({ query, mutation, ...args }: Query | Mutation) => {
const test = ({
query,
mutation,
...args
}: (Query | Mutation) &
Omit<Parameters<typeof server.executeOperation>[0], 'query'>) => {
const operation = query || mutation;

if (!operation || (query && mutation)) {
Expand Down

0 comments on commit 81b9aa9

Please sign in to comment.