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

Breaking typescript change in 2.5 #2824

Closed
VincentLanglet opened this issue Feb 27, 2019 · 4 comments · Fixed by #2832
Closed

Breaking typescript change in 2.5 #2824

VincentLanglet opened this issue Feb 27, 2019 · 4 comments · Fixed by #2832

Comments

@VincentLanglet
Copy link

In 2.4.1, this was valid:

import { Context } from 'react-apollo';

In 2.5, it's now

import { Context } from 'react-apollo/walkTree';

I think it's because of this commit 66b0945

The walkTree definitions are not exported in index.d.ts

@benjamn
Copy link
Member

benjamn commented Mar 1, 2019

This change was documented in the changelog for 2.4.0: https://github.com/apollographql/react-apollo/blob/master/Changelog.md#240

@VincentLanglet
Copy link
Author

I had no use of the walkTree. Only the Context type.

import { GraphQLRequest } from 'apollo-link';
import { setContext } from 'apollo-link-context';
import { Context } from 'react-apollo';

import authenticator from '../../services/authenticator';

export const authorize = (_: GraphQLRequest, context: Context): Context => {
  const token = authenticator.getUserToken();

  if (!token) {
    return context;
  }

  return {
    ...context,
    headers: {
      ...context.headers,
      Authorization: `Bearer ${token}`,
    },
  };
};

export default setContext(authorize);

The fact walkTree is deprecated, shouldn't deprecate the Context type.
Maybe should it be defined somewhere else.

benjamn added a commit that referenced this issue Mar 1, 2019
When we stopped reexporting everything from walkTree.ts as part of #2533,
we also stopped exporting the Context type that it uses.

Moving the declaration and export of Context from walkTree.ts to types.ts
restores the ability to do

  import { Context } from "react-apollo"

which should fix #2824.
@benjamn
Copy link
Member

benjamn commented Mar 1, 2019

@VincentLanglet Ahh, I agree it was a mistake to stop exporting that Context interface. Does #2832 look like it will restore the previous behavior?

@VincentLanglet
Copy link
Author

Yes, I think it'll be good since index has export * from './types';

benjamn added a commit that referenced this issue Mar 1, 2019
When we stopped reexporting everything from walkTree.ts as part of #2533,
we also stopped exporting the Context type that it uses.

Moving the declaration and export of Context from walkTree.ts to types.ts
restores the ability to do

  import { Context } from "react-apollo"

which should fix #2824.
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 a pull request may close this issue.

2 participants