Skip to content

Commit

Permalink
core: fix sha import and fix persisted query cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
evans committed Jun 11, 2018
1 parent 3ef3e47 commit ae8ef9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
4 changes: 3 additions & 1 deletion packages/apollo-server-core/src/ApolloServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,14 +905,16 @@ describe('ApolloServerBase', () => {
server = new ApolloServerBase({
schema,
introspection: false,
persistedQueries: {
cache: new Map<string, string>() as any,
},
});

const httpServer = createHttpServer(server);

server.use({
getHttp: () => httpServer,
path: '/graphql',
cache: new Map<string, string>() as any,
});
uri = (await server.listen()).url;
});
Expand Down
33 changes: 17 additions & 16 deletions packages/apollo-server-core/src/runHttpQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutionResult } from 'graphql';
import * as sha256 from 'hash.js/lib/hash/sha/256';
import sha256 from 'hash.js/lib/hash/sha/256';

import { runQuery, QueryOptions } from './runQuery';
import {
Expand Down Expand Up @@ -198,21 +198,22 @@ export async function runHttpQuery(
}

//Do the store completely asynchronously
Promise.resolve().then(() => {
//We do not wait on the cache storage to complete
optionsObject.persistedQueries.cache
.set(sha, queryString)
.catch(error => {
if (optionsObject.logFunction) {
optionsObject.logFunction({
action: LogAction.setup,
step: LogStep.status,
key: 'error',
data: error,
});
}
});
});
Promise.resolve()
.then(() => {
//We do not wait on the cache storage to complete
return optionsObject.persistedQueries.cache.set(sha, queryString);
})
.catch(error => {
console.log(error);
if (optionsObject.logFunction) {
optionsObject.logFunction({
action: LogAction.setup,
step: LogStep.status,
key: 'error',
data: error,
});
}
});
}
}

Expand Down

0 comments on commit ae8ef9a

Please sign in to comment.