Skip to content

Commit

Permalink
fix(graphql): Instantiate dataSources for each apollo request
Browse files Browse the repository at this point in the history
  • Loading branch information
bsparks authored and Romakita committed Apr 1, 2020
1 parent d274036 commit a8a5c30
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions packages/graphql/src/services/GraphQLService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ describe("GraphQLService", () => {

result2.should.deep.eq(result1);
result1.args.should.deep.eq([{schema: {schema: "schema"}, dataSources: noop}]);
service.createSchema.should.have.been.calledOnceWithExactly({resolvers: [], container: service.injectorService});
service.createSchema.should.have.been.calledOnceWithExactly({
resolvers: [],
container: service.injectorService
});
result1.applyMiddleware.should.have.been.calledOnceWithExactly(
Sinon.match({
app: Sinon.match.func,
Expand Down Expand Up @@ -99,7 +102,10 @@ describe("GraphQLService", () => {
} as any);

result.args.should.deep.eq([{schema: {schema: "schema"}, dataSources: noop}]);
service.createSchema.should.have.been.calledOnceWithExactly({resolvers: [], container: service.injectorService});
service.createSchema.should.have.been.calledOnceWithExactly({
resolvers: [],
container: service.injectorService
});

result.applyMiddleware.should.have.been.calledOnceWithExactly(
Sinon.match({
Expand Down Expand Up @@ -164,4 +170,31 @@ describe("GraphQLService", () => {
fn().should.deep.eq({});
}));
});
describe("getDataSources", () => {
class DataSource {}

let service: any;
before(
inject([GraphQLService], (_service: any) => {
service = _service;
sandbox.stub(service.injectorService, "getProviders").returns([
{
name: DataSource.name,
provide: DataSource
}
]);
sandbox.stub(service.injectorService, "invoke").returns(new DataSource());
})
);
after(() => {
sandbox.restore();
});
it("should return a function with all dataSources", () => {
const result = service.getDataSources();

result.should.deep.eq({
dataSource: new DataSource()
});
});
});
});

0 comments on commit a8a5c30

Please sign in to comment.