Can you show me an example of how can i test my middlewares?
I want to test that my queries can only be accessed if the correct jwt token is passed through the request Authorization header. I'm using graphql-yoga middleware. Here's an example of my graphql server:
const server = new GraphQLServer({
typeDefs: './src/schemas/schema.graphql',
resolvers,
middlewares: [permissions], // <-- here's where I pass in my middleware
context: request => {
return {
...request,
prisma,
};
},
});
Here's what I intend to do, e.g.:
test('only authorized user can see this', async () => {
const query = `
query user($id: ID!){
user(id: $id) {
id
email
name
}
}
`;
const args = {
id: 'foo-bar-id',
};
const result = await tester.graphql(
query,
{},
{ prisma },
args,
);
expect(result.errors[0].message).to.be.eq(
'Error!! Unauthorized request',
);
Can you show me an example of how can i test my middlewares? I want to test that my queries can only be accessed if the correct jwt token is passed through the request Authorization header. I'm using graphql-yoga middleware. Here's an example of my graphql server:
Here's what I intend to do, e.g.: