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

Commit

Permalink
Fix lodash.* packages - remove re-export compose (#1478)
Browse files Browse the repository at this point in the history
* first lock down bundle size

* Remove lodash.* packages and use lodash/* packages - identical bundle size

* Remove re-export of flowright due to loss of types (exports as `any`)

* fix import/usage of compose

* fix inconsistency with flow types QueryProps -> GraphqlQueryControls

* fix some jest configurations - no idea why module resolution is failing on travis

* remove unused lodash-es from jest transformIgnore

* add ref to PR in changelog

* change capitalization on flowRight
  • Loading branch information
rosskevin authored Dec 27, 2017
1 parent e257199 commit 08cb715
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 60 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ first three params (`TChildProps` can be derived). [#1402](https://github.com/ap
- Remove deprecated `operationOptions.options.skip`, use `operationOptions.skip` instead
- Rename type `ProviderProps` to `ApolloProviderProps` [#1467](https://github.com/apollographql/react-apollo/pull/1467)
- Rename `getDataFromTree` type `QueryResult` to `QueryTreeResult` [#1467](https://github.com/apollographql/react-apollo/pull/1467)
- Rename type `QueryProps` to `GraphqlQueryControls` [#1467](https://github.com/apollographql/react-apollo/pull/1467)
- Rename type `QueryProps` to `GraphqlQueryControls` [#1467](https://github.com/apollographql/react-apollo/pull/1467) [#1478](https://github.com/apollographql/react-apollo/pull/1478)
- Remove re-export of `compose` (a.k.a. `lodash/flowright`) as it is loses types (exports as `any`). Users may choose to use `lodash/flowright` or `recompose/compose` themselves based on their use case. [#1478](https://github.com/apollographql/react-apollo/pull/1478)

- **Other Changes**
- Update all dependencies, scripts' usage, prettier and typescript setup [#1402](https://github.com/apollographql/react-apollo/pull/1402)
Expand Down
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"bundlesize": [
{
"path": "./lib/umd/react-apollo.js",
"threshold": "1 Kb"
"maxSize": "4.7 KB"
}
],
"lint-staged": {
Expand Down Expand Up @@ -54,17 +54,15 @@
"preset": "react-native",
"testEnvironment": "jsdom",
"transform": {
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest/preprocessor.js",
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "babel-jest"
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!(lodash-es|react-native)/)"
],
"transformIgnorePatterns": ["<rootDir>/node_modules/(?!(react-native)/)"],
"mapCoverage": true,
"moduleFileExtensions": ["ts", "tsx", "js", "json"],
"modulePathIgnorePatterns": [
"<rootDir>/examples",
"<rootDir>/test/flow.js",
"<rootDir>/test/flow-usage.js",
"<rootDir>/test/typescript-usage.tsx"
],
"projects": ["<rootDir>"],
Expand Down Expand Up @@ -103,7 +101,6 @@
"jest": "21.2.1",
"jsdom": "11.5.1",
"lint-staged": "6.0.0",
"lodash": "4.17.4",
"pre-commit": "1.2.2",
"prettier": "1.9.2",
"react": "16.2.0",
Expand All @@ -125,8 +122,7 @@
"fbjs": "^0.8.16",
"hoist-non-react-statics": "^2.3.1",
"invariant": "^2.2.2",
"lodash.flowright": "^3.5.0",
"lodash.pick": "^4.4.0",
"lodash": "4.17.4",
"prop-types": "^15.6.0"
}
}
2 changes: 1 addition & 1 deletion src/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { parser, DocumentType } from './parser';

const shallowEqual = require('fbjs/lib/shallowEqual');
const invariant = require('invariant');
const pick = require('lodash.pick');
const pick = require('lodash/pick');

function observableQueryFields(observable) {
const fields = pick(
Expand Down
2 changes: 1 addition & 1 deletion src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
const shallowEqual = require('fbjs/lib/shallowEqual');
const invariant = require('invariant');
const assign = require('object-assign');
const pick = require('lodash.pick');
const pick = require('lodash/pick');
const hoistNonReactStatics = require('hoist-non-react-statics');

const defaultMapPropsToOptions = () => ({});
Expand Down
9 changes: 4 additions & 5 deletions src/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import type {
} from 'apollo-client';
import type { DocumentNode, VariableDefinitionNode } from 'graphql';
import gql from 'graphql-tag';
import compose from 'lodash.flowright';

// export everything from apollo-client
export * from 'apollo-client';
export { gql, compose };
export { gql };

export interface ProviderProps {
client: ApolloClient;
Expand All @@ -42,7 +41,7 @@ export type MutationFunc<TResult> = (
) => Promise<ApolloQueryResult<TResult>>;

export type ChildProps<P, R> = {
data: QueryProps & R,
data: GraphqlQueryControls & R,
mutate: MutationFunc<R>,
} & P;

Expand All @@ -65,7 +64,7 @@ export interface QueryOpts {
skip?: boolean;
}

export interface QueryProps {
export interface GraphqlQueryControls {
error?: ApolloError;
networkStatus: number;
loading: boolean;
Expand All @@ -84,7 +83,7 @@ export interface QueryProps {

export interface OptionProps<TProps, TResult> {
ownProps: TProps;
data: QueryProps & TResult;
data: GraphqlQueryControls & TResult;
mutate: MutationFunc<TResult>;
}

Expand Down
4 changes: 0 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ export * from './graphql';
export { default as withApollo } from './withApollo';

export * from './types';

// expose easy way to join queries from redux
import * as compose from 'lodash.flowright';
export { compose };
4 changes: 2 additions & 2 deletions test/client/graphql/mutations/queries.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { mockSingleLink } from '../../../../src/test-utils';
import {
ApolloProvider,
graphql,
compose,
ChildProps,
MutationFunc,
} from '../../../../src';

import stripSymbols from '../../../test-utils/stripSymbols';

const compose = require('lodash/flowRight');

describe('[mutations] query integration', () => {
it('allows for passing optimisticResponse for a mutation', done => {
const query = gql`
Expand Down
3 changes: 2 additions & 1 deletion test/client/graphql/shared-operations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {
DataValue,
graphql,
withApollo,
compose,
} from '../../../src';
import * as TestUtils from 'react-dom/test-utils';

const compose = require('lodash/flowRight');

describe('shared operations', () => {
describe('withApollo', () => {
it('passes apollo-client to props', () => {
Expand Down
14 changes: 9 additions & 5 deletions test/flow-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
// @flow
import gql from 'graphql-tag';
import React from 'react';
import { withApollo, compose, graphql } from '../src';
import type { OperationComponent, QueryProps, ChildProps } from '../src';
import { withApollo, graphql } from '../src';
import type {
OperationComponent,
GraphqlQueryControls,
ChildProps,
} from '../src';

const query = gql`
{
Expand Down Expand Up @@ -59,7 +63,7 @@ const BasicClassWithData = withData(BasicComponent);
// A class component with it's own variable
type CmplxOwnProps = {| faz: string |};
type CmplxComponentProps = {
data: QueryProps & IQuery,
data: GraphqlQueryControls & IQuery,
mutate: any, // The mutation is actually required or we get a error at the withData
} & CmplxOwnProps;
class CmplxComponent extends React.Component<CmplxComponentProps> {
Expand All @@ -86,7 +90,7 @@ const CmplxWithData = withFancyData(CmplxComponent);
// since we don't rely on the ChildProps<P, R> we don't need the mutate: any
type Cmplx2OwnProps = { faz: string }; // We can have exact own props as we don't rely on the TMergedProps
type Cmplx2ComponentProps = {
data: IQuery & QueryProps,
data: IQuery & GraphqlQueryControls,
} & Cmplx2OwnProps;
class Cmplx2Component extends React.Component<Cmplx2ComponentProps> {
render() {
Expand Down Expand Up @@ -137,7 +141,7 @@ type Response = {
hero: Hero,
};

type Props = Response & QueryProps;
type Props = Response & GraphqlQueryControls;

export type InputProps = {
episode: string,
Expand Down
22 changes: 0 additions & 22 deletions typings/lodash.d.ts

This file was deleted.

10 changes: 1 addition & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3928,10 +3928,6 @@ lodash.flattendeep@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2"

lodash.flowright@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/lodash.flowright/-/lodash.flowright-3.5.0.tgz#2b5fff399716d7e7dc5724fe9349f67065184d67"

lodash.includes@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f"
Expand Down Expand Up @@ -3976,10 +3972,6 @@ lodash.padstart@^4.1.0:
version "4.6.1"
resolved "https://registry.yarnpkg.com/lodash.padstart/-/lodash.padstart-4.6.1.tgz#d2e3eebff0d9d39ad50f5cbd1b52a7bce6bb611b"

lodash.pick@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3"

lodash.restparam@^3.0.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
Expand Down Expand Up @@ -6060,7 +6052,7 @@ vinyl@^0.5.0:
clone-stats "^0.0.1"
replace-ext "0.0.1"

vm2@patriksimek/vm2#custom_files:
"vm2@github:patriksimek/vm2#custom_files":
version "3.5.0"
resolved "https://codeload.github.com/patriksimek/vm2/tar.gz/7e82f90ac705fc44fad044147cb0df09b4c79a57"

Expand Down

0 comments on commit 08cb715

Please sign in to comment.