Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed two queries in flight bug for Apollo Link #2002

Merged
merged 2 commits into from
Aug 7, 2017
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 @@ -2,6 +2,8 @@

### vNEXT

-fixed `resolved` scoping issue for multiple queries in flight with Apollo Link [PR #2002](https://github.com/apollographql/apollo-client/pull/2002)

### 1.9.0
- Move to `apollo-link-core` from `apollo-link` to reduce bundle size [PR #1955](https://github.com/apollographql/apollo-client/pull/1955)
- Document ApolloClient.prototype.subscribe [PR #1932](https://github.com/apollographql/apollo-client/pull/1932)
Expand Down
2 changes: 1 addition & 1 deletion src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ export default class ApolloClient implements DataProxy {
const createQuery = (
getResult: (request: Request) => Observable<ExecutionResult>,
) => {
let resolved = false;
return (request: Request) =>
new Promise<ExecutionResult>((resolve, reject) => {
let resolved = false;
const subscription = getResult(request).subscribe({
next: (data: ExecutionResult) => {
if (!resolved) {
Expand Down
81 changes: 81 additions & 0 deletions test/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,87 @@ describe('client', () => {
});
});

it(
'should allow multiple queries with an apollo-link enabled network interface',
done => {
const query = gql`
query people {
allPeople(first: 1) {
people {
name
__typename
}
__typename
}
}
`;

const query2 = gql`
query people {
people {
id
}
}
`;

const data = {
allPeople: {
people: [
{
name: 'Luke Skywalker',
__typename: 'Person',
},
],
__typename: 'People',
},
};

const data2 = {
people: {
id: 'People',
},
};

const variables = { first: 1 };

const networkInterface = ApolloLink.from([
operation => {
if (operation.query === query) {
return Observable.of({
data,
});
} else {
return Observable.of({
data: data2,
});
}
},
]);

const client = new ApolloClient({
networkInterface,
addTypename: false,
});

let done1 = false,
done2 = false;
client.query({ query, variables }).then(actualResult => {
assert.deepEqual(actualResult.data, data);
done1 = true;
if (done2) {
done();
}
});
client.query({ query: query2, variables }).then(actualResult2 => {
assert.deepEqual(actualResult2.data, data2);
done2 = true;
if (done1) {
done();
}
});
},
);

it('should allow for a single query with complex default variables to take place', () => {
const query = gql`
query stuff(
Expand Down