You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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',
);
The text was updated successfully, but these errors were encountered:
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.:
The text was updated successfully, but these errors were encountered: