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

Pass component display name to watchQuery metadata. #363

Merged
merged 1 commit into from
Dec 9, 2016
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
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