Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Revert "Use Partial<TData> rather than TData | {} (#2313)" #2423

Merged
merged 2 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ function observableQueryFields<TData, TVariables>(
export interface QueryResult<TData = any, TVariables = OperationVariables>
extends ObservableQueryFields<TData, TVariables> {
client: ApolloClient<any>;
data: Partial<TData>;
// we create an empty object to make checking for data
// easier for consumers (i.e. instead of data && data.user
// you can just check data.user) this also makes destructring
// easier (i.e. { data: { user } })
// however, this isn't realy possible with TypeScript that
// I'm aware of. So intead we enforce checking for data
// like so result.data!.user. This tells TS to use TData
// XXX is there a better way to do this?
data: TData | {};
error?: ApolloError;
loading: boolean;
networkStatus: NetworkStatus;
Expand Down
2 changes: 1 addition & 1 deletion src/query-hoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function query<
// we massage the Query components shape here to replicate that
const result = Object.assign(r, data || {});
const name = operationOptions.name || 'data';
let childProps: TChildProps = { [name]: result } as any;
let childProps = { [name]: result };
if (operationOptions.props) {
const newResult: OptionProps<TProps, TData, TGraphQLVariables> = {
[name]: result,
Expand Down
2 changes: 1 addition & 1 deletion test/client/Query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ describe('Query component', () => {
function Container() {
return (
<AllPeopleQuery2 query={query} notifyOnNetworkStatusChange>
{result => {
{(result: any) => {
try {
switch (count++) {
case 0:
Expand Down
4 changes: 2 additions & 2 deletions test/client/getDataFromTree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ describe('SSR', () => {

const WrappedElement = () => (
<CurrentUserQuery query={query}>
{({ data, loading }) => (
{({ data, loading }: { data: Data; loading: boolean }) => (
<div>{loading || !data ? 'loading' : data.currentUser!.firstName}</div>
)}
</CurrentUserQuery>
Expand Down Expand Up @@ -1291,7 +1291,7 @@ describe('SSR', () => {

const Element = (props: { id: string }) => (
<CurrentUserQuery query={query} ssr={false} variables={props}>
{({ data, loading }) => (
{({ data, loading }: { data: Data; loading: boolean }) => (
<div>{loading || !data ? 'loading' : data.currentUser!.firstName}</div>
)}
</CurrentUserQuery>
Expand Down