Skip to content

Improved type definitions for the observable query#3140

Merged
hwillson merged 8 commits intoapollographql:masterfrom
excitement-engineer:improve-types
Jun 1, 2018
Merged

Improved type definitions for the observable query#3140
hwillson merged 8 commits intoapollographql:masterfrom
excitement-engineer:improve-types

Conversation

@excitement-engineer
Copy link
Copy Markdown
Contributor

The Query component in react-apollo improved upon the typescript definitions provided by apollo-client.

I am now porting these improvements back to apollo-client so that all users can benefit from these improvements and so that react-apollo can simply import the type definitions directly from apollo-client.

This PR makes introduce generic types for the data TData and variables TVariables in the ObservableQuery class.

@apollo-cla
Copy link
Copy Markdown

apollo-cla commented Mar 10, 2018

Warnings
⚠️

There are library changes, but not tests. That's OK as long as you're refactoring existing code

Generated by 🚫 dangerJS

*/
public setVariables(
variables: any,
variables?: TVariables,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is this supposed to be nullable. The type was any before so anything was allowed. If I make the variables nonnull here then I get typescript errors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I don't the the intention is for it to be nullable here. What issues did you run into?

fetchMoreResult?: { [key: string]: any };
variables: { [key: string]: any };
fetchMoreResult?: TData;
variables?: TVariables;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is this supposed to be nullable? It wasn't before but typescript is giving me errors if I make this nonnull.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@excitement-engineer what errors did you get?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but, yes variables can be null here

@excitement-engineer
Copy link
Copy Markdown
Contributor Author

@jbaxleyiii @leoasis

Copy link
Copy Markdown
Contributor

@jbaxleyiii jbaxleyiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@excitement-engineer lets figure out the setVariables bit, but otherwise YAYAYAYA

fetchMoreResult?: { [key: string]: any };
variables: { [key: string]: any };
fetchMoreResult?: TData;
variables?: TVariables;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@excitement-engineer what errors did you get?

fetchMoreResult?: { [key: string]: any };
variables: { [key: string]: any };
fetchMoreResult?: TData;
variables?: TVariables;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but, yes variables can be null here

*/
public setVariables(
variables: any,
variables?: TVariables,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I don't the the intention is for it to be nullable here. What issues did you run into?

@jbaxleyiii
Copy link
Copy Markdown
Contributor

oh @excitement-engineer could you add a changelog here as well? Thanks!

const doc = getDirectivesFromDocument([{ name: 'client' }], query, true);
expect(print(doc)).toBe(print(expected));
});
});
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was missing in apollo-client. This was causing the prettier pre-commit hook to fail...

): Promise<ApolloQueryResult<TData>> {
// since setVariables restarts the subscription, we reset the tornDown status
this.isTornDown = false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the line below here we are doing:

const newVariables = variables ? variables : this.variables;

So I am wondering if it isn't possible to make the type variables?: TVariables?


return this.setVariables(
this.options.variables,
this.options.variables as TVariables,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the issue I ran into with setVariables having a non-null TVariables type. this.options.variables is nullable here so I had to make an explicit cast to get typescript to work

@hwillson hwillson self-assigned this Jun 1, 2018
Copy link
Copy Markdown
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all of your work on this @excitement-engineer! We should be all set here, so LGTM!

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.

4 participants