Skip to content

Commit

Permalink
1.9.2 and prettier updates
Browse files Browse the repository at this point in the history
  • Loading branch information
James Baxley committed Aug 31, 2017
1 parent 2bd98ec commit a70d458
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 186 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change log

### vNEXT

### 1.9.2
- Fix FetchMoreQueryOptions and IntrospectionResultData flow annotations [PR #2034](https://github.com/apollographql/apollo-client/pull/2034)
- Fix referential equality bug for queries with custom resolvers [PR #2053](https://github.com/apollographql/apollo-client/pull/2053)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-client",
"version": "1.9.1",
"version": "1.9.2",
"description": "A simple yet functional GraphQL client.",
"main": "./lib/apollo.umd.js",
"module": "./lib/src/index.js",
Expand Down
11 changes: 4 additions & 7 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,10 @@ export class ObservableQuery<T> extends Observable<ApolloQueryResult<T>> {

// Use the same options as before, but with new variables
return this.queryManager
.fetchQuery(
this.queryId,
{
...this.options,
variables: this.variables,
} as WatchQueryOptions,
)
.fetchQuery(this.queryId, {
...this.options,
variables: this.variables,
} as WatchQueryOptions)
.then(result => maybeDeepFreeze(result));
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/queries/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,17 @@ export class QueryStore {
.filter(queryId => {
return observableQueryIds.indexOf(queryId) > -1;
})
.reduce((res, key) => {
// XXX set loading to true so listeners don't trigger unless they want results with partial data
res[key] = {
...this.store[key],
networkStatus: NetworkStatus.loading,
};

return res;
}, {} as { [queryId: string]: QueryStoreValue });
.reduce(
(res, key) => {
// XXX set loading to true so listeners don't trigger unless they want results with partial data
res[key] = {
...this.store[key],
networkStatus: NetworkStatus.loading,
};

return res;
},
{} as { [queryId: string]: QueryStoreValue },
);
}
}
169 changes: 79 additions & 90 deletions test/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,9 @@ describe('client', () => {

// shouldn't throw
createStore(
combineReducers(
{
testApollo: client.reducer(),
} as any,
),
combineReducers({
testApollo: client.reducer(),
} as any),
// here "client.setStore(store)" will be called internally,
// this method throws if "reduxRootSelector" or "reduxRootKey"
// are not configured properly
Expand Down Expand Up @@ -212,13 +210,9 @@ describe('client', () => {
const client = new ApolloClient();

assert.throws(() => {
client.query(
gql`
{
a
}
` as any,
);
client.query(gql`{
a
}` as any);
}, 'query option is required. You must specify your GraphQL document in the query option.');
assert.throws(() => {
client.query({ query: '{ a }' } as any);
Expand All @@ -229,15 +223,13 @@ describe('client', () => {
const client = new ApolloClient();

assert.throws(() => {
client.mutate(
{
query: gql`
{
a
}
`,
} as any,
);
client.mutate({
query: gql`
{
a
}
`,
} as any);
}, 'mutation option is required. You must specify your GraphQL document in the mutation option.');
});

Expand Down Expand Up @@ -315,86 +307,83 @@ 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
}
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 query2 = gql`
query people {
people {
id
}
`;
}
`;

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

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

const variables = { first: 1 };
const variables = { first: 1 };

const networkInterface = ApolloLink.from([
operation => {
if (operation.query === query) {
return Observable.of({
data,
});
} else {
return Observable.of({
data: data2,
});
}
},
]);
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,
});
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();
}
});
},
);
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`
Expand Down
93 changes: 41 additions & 52 deletions test/deduplicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ describe('query deduplication', () => {
};

let called = 0;
const deduper = new Deduplicator(
{
query: () => {
called += 1;
return new Promise((resolve, reject) => {
setTimeout(resolve, 5);
});
},
} as any,
);
const deduper = new Deduplicator({
query: () => {
called += 1;
return new Promise((resolve, reject) => {
setTimeout(resolve, 5);
});
},
} as any);

deduper.query(request1);
deduper.query(request2);
Expand All @@ -62,28 +60,23 @@ describe('query deduplication', () => {
};

let called = 0;
const deduper = new Deduplicator(
{
query: () => {
called += 1;
switch (called) {
case 1:
return new Promise((resolve, reject) => {
setTimeout(reject);
});
case 2:
return new Promise((resolve, reject) => {
setTimeout(resolve);
});
default:
return assert(
false,
'Should not have been called more than twice',
);
}
},
} as any,
);
const deduper = new Deduplicator({
query: () => {
called += 1;
switch (called) {
case 1:
return new Promise((resolve, reject) => {
setTimeout(reject);
});
case 2:
return new Promise((resolve, reject) => {
setTimeout(resolve);
});
default:
return assert(false, 'Should not have been called more than twice');
}
},
} as any);

return deduper.query(request).catch(() => {
deduper.query(request);
Expand Down Expand Up @@ -113,16 +106,14 @@ describe('query deduplication', () => {
};

let called = 0;
const deduper = new Deduplicator(
{
query: () => {
called += 1;
return new Promise((resolve, reject) => {
setTimeout(resolve, 5);
});
},
} as any,
);
const deduper = new Deduplicator({
query: () => {
called += 1;
return new Promise((resolve, reject) => {
setTimeout(resolve, 5);
});
},
} as any);

deduper.query(request1);
deduper.query(request2);
Expand Down Expand Up @@ -151,16 +142,14 @@ describe('query deduplication', () => {
};

let called = 0;
const deduper = new Deduplicator(
{
query: () => {
called += 1;
return new Promise((resolve, reject) => {
setTimeout(resolve, 5);
});
},
} as any,
);
const deduper = new Deduplicator({
query: () => {
called += 1;
return new Promise((resolve, reject) => {
setTimeout(resolve, 5);
});
},
} as any);

deduper.query(request1, false);
deduper.query(request2, false);
Expand Down
Loading

1 comment on commit a70d458

@jamesreggio
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for releasing. (I think you forgot to tag the release, though.)

Please sign in to comment.