Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix createTestClient types #2566

Closed

Conversation

borekb
Copy link
Contributor

@borekb borekb commented Apr 12, 2019

The problem

I was following this documentation which shows code like this:

const { createTestClient } = require('apollo-server-testing');
const { query, mutate } = createTestClient(server);

query({
  query: GET_USER,
  variables: { id: 1 }
});

When I tried that, TypeScript complained about the variables object. This can be also replicated by opening the createTestClient.test.ts file:

Screenshot 2019-04-12 at 18 47 00

The fix

To fix this, I've updated the typing of the test function in 62bea35. With this and another fix in 4ccc129, the createTestClient.test.ts file is clear of any errors.

VSCode experience

The experience when typing a call site code seems to be good. Initially, it offer all three properties:

Screenshot 2019-04-12 at 18 54 37

Once a query or a mutation is chosen, it narrows down suggestions to only variables:

Screenshot 2019-04-12 at 18 55 54

Providing both is an error:

Screenshot 2019-04-12 at 18 56 38

Adding variables is valid:

Screenshot 2019-04-12 at 18 57 43

It is done using function overloads which I generally don't like very much but maybe here, it's a good use case for them.

Is the change from ...rest to variables OK?

The code now only allows (strongly-typed) variables while previously, it worked with ...rest. Is this change OK? I think it should be as the tests don't show any other use case but it's a change in functionality so I thought I'd rather ask.

TODO

  • (probably not necessary?) Update CHANGELOG.md with your change (include reference to issue & this PR)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass. (I'm not quite sure how to do that only for the apollo-server-testing but I've ran all tests in this package and they are green.)

borekb added 3 commits April 12, 2019 16:15
- `variables` can now be used from call sites
- The "Query XOR Mutation" nature of the object is now described using function overloads.
- No more `...args` – only `variables` are explicitly supported.

As a result, `createTestClient.test.ts` is now error-free.
@borekb
Copy link
Contributor Author

borekb commented Jun 5, 2019

#2307 seems to be resolving the same issue, in another way, technically, but I think we can close this.

@borekb borekb closed this Jun 5, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant