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

Commit

Permalink
Pass component display name to watchQuery metadata. (#363)
Browse files Browse the repository at this point in the history
Metadata is a new feature added in [email protected]. It's OK to pass
the option in to older clients; it will just be ignored.

This will be used by Apollo Chrome DevTools!
  • Loading branch information
glasser authored and James Baxley committed Dec 9, 2016
1 parent fc3ec89 commit 02fe991
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 233 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { getDataFromTree, renderToStringWithData } from 'react-apollo'

- Feature: Add networkStatus prop to connected components[Issue #322](https://github.com/apollostack/react-apollo/issues/322)

- Feature: Pass component display name as watchQuery metadata for experimental devtools [PR #363](https://github.com/apollostack/react-apollo/pull/363)

- Bug: fix issue with Redux's `connect` and SSR - [Issue #350](https://github.com/apollostack/react-apollo/issues/350)

### v0.6.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"@types/redux-form": "^4.0.29",
"@types/redux-immutable": "^3.0.30",
"@types/sinon": "^1.16.29",
"apollo-client": "0.5.11",
"apollo-client": "0.5.13",
"babel-jest": "^14.1.0",
"babel-preset-react-native": "^1.9.0",
"browserify": "^13.0.0",
Expand Down
5 changes: 5 additions & 0 deletions src/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ export default function graphql(
} else {
this.queryObservable = this.client.watchQuery(assign({
query: document,
metadata: {
reactComponent: {
displayName: graphQLDisplayName,
},
},
}, opts));
}
}
Expand Down
35 changes: 34 additions & 1 deletion test/react-web/client/graphql/queries.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1968,5 +1968,38 @@ describe('queries', () => {
};

mount(<ApolloProvider client={client}><Container /></ApolloProvider>);
});
});

it('stores the component name in the query metadata', (done) => {
const query = gql`query people { allPeople(first: 1) { people { name } } }`;
const data = { allPeople: { people: [ { name: 'Luke Skywalker' } ] } };
const networkInterface = mockNetworkInterface({ request: { query }, result: { data } });
const client = new ApolloClient({ networkInterface, addTypename: false });

@graphql(query)
class Container extends React.Component<any, any> {
componentWillReceiveProps(props) {
const queries = client.queryManager.getApolloState().queries;
const queryIds = Object.keys(queries);
expect(queryIds.length).toEqual(1);
const query = queries[queryIds[0]];
expect(query.metadata).toEqual({
reactComponent: {
displayName: 'Apollo(Container)',
},
});
done();
}
render() {
return null;
}
}

renderer.create(
<ApolloProvider client={client}>
<Container />
</ApolloProvider>
);
});

});
Loading

0 comments on commit 02fe991

Please sign in to comment.