I am not getting request from the context, this is my server file.
export async function buildTestServer({
user,
headers,
roles,
}: {
user?: User;
headers?: { [key: string]: string };
roles?: Role;
}) {
const server = new ApolloServer({
schema,
context: async ({ req }) => {
const authHeader = headers?.authorization;
const token = extractTokenFromAuthenticationHeader(authHeader);
try {
const user = await new UserPermissionsService(token).call();
return { req, user };
} catch {
return { req };
}
}
And this is my test file from where I building the server and calling the resolver to test, but I am not getting the request.
const GET_LIST = `
query GetList($listId: String!) {
GetList(listId: $listId) {
id
}
}
`;
test('Get Lists', async () => {
const customer = await CustomerFactory.create();
const user = await UserFactory.create({ customerId: customer.id });
const list = await ListFactory.create({
customerId: customer.id,
});
const server = await buildTestServer({ user });
const result = await server.executeOperation({
query: GET_LIST,
variables: {
listId: list.id
},
});
console.log("check list error", JSON.stringify(result));
var length = Object.keys(result.data?.GetLists).length;
expect(length).toBeGreaterThan(0);
});