My contextValues / dataSources don’t seem to be coming through on my jest tests. When I console.log in the actual resolver, I see the dataSource, but the expect returns null. Also, aside – is it always required to assert a single king in order to retrieve the data? This is strange.
Here is my Test Server:
const schema = makeExecutableSchema({
resolvers,
resolverValidationOptions: { requireResolversForResolveType: 'ignore' },
typeDefs,
});
interface ServerContext {
token?: String;
dataSources: MockedDataSourcesTypes;
}
export const apolloTestServer = new ApolloServer<ServerContext>({
schema,
});
Here is a Query resolver function
geThingById: async (_, { id }, { dataSources }) => {
const { data } = await dataSources.thing.getThing(id);
console.log('DATA -- this returns with dataSources', data, dataSources);
return data;
},
Here is my test:
describe('getThing', () => {
it('return the correct query response', async () => {
const { body } = await apolloTestServer.executeOperation(
{ query: queries.geThingById },
{ contextValue: { dataSources: mockedDataSources } }
);
assert(body.kind === 'single');
expect(body.singleResult).toMatchObject({
errors: undefined,
data: {
geThingById: {...myData}
}
});
});
});
The console returns well, but data.getThing is null. Wondering if I’m missing something