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

Commit

Permalink
Added an explicit nested queries test
Browse files Browse the repository at this point in the history
(trying to replicate #250)
  • Loading branch information
tmeasday committed Oct 17, 2016
1 parent b6612f9 commit 39e950e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/react-web/server/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ describe('SSR', () => {
});
});

it('should handle nested queries that depend on each other', () => {
const idQuery = gql`{ currentUser { id } }`;
const idData = { currentUser: { id: '1234' } };
const userQuery = gql`query getUser($id: String) { user(id: $id) { firstName } }`;
const variables = { id: '1234' };
const userData = { user: { firstName: 'James' } };
const networkInterface = mockNetworkInterface(
{ request: { query: idQuery }, result: { data: idData }, delay: 50 },
{ request: { query: userQuery, variables }, result: { data: userData }, delay: 50 },
);
const apolloClient = new ApolloClient({ networkInterface });

const withId = graphql(idQuery);
const withUser = graphql(userQuery, {
skip: ({ data: { loading } }) => loading,
options: ({ data }) => ({ variables: { id: data.currentUser.id } }),
});
const Component = ({ data }) => (
<div>{data.loading ? 'loading' : data.user.firstName}</div>
);
const WrappedComponent = withId(withUser(Component));

const app = (<ApolloProvider client={apolloClient}><WrappedComponent /></ApolloProvider>);

return getDataFromTree(app)
.then(() => {
const markup = ReactDOM.renderToString(app);
expect(markup).toMatch(/James/);
});
});

it('should correctly skip queries (deprecated)', () => {

const query = gql`{ currentUser { firstName } }`;
Expand Down

0 comments on commit 39e950e

Please sign in to comment.