Skip to content

Commit

Permalink
Add tests for middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Nov 29, 2018
1 parent d43271b commit 24eac3d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/core/tests/graphql-module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,26 @@ describe('GraphQLModule', () => {
expect(result.data['bar'].content).toBe('BAR');
});
});
it('should mutate schema using middleware', async () => {
const { schema, context } = new GraphQLModule({
typeDefs: gql`
type Query {
foo: Boolean
}
`,
resolvers: {
Query: {
foo: (root, args, context, info) => !!info.schema['__DIRTY__'],
},
},
middleware: ({schema}) => { schema['__DIRTY__'] = true; return { schema }; },
});
const result = await execute({
schema,
document: gql`query { foo }`,
contextValue: await context({ req: {} }),
});
expect(result.errors).toBeFalsy();
expect(result.data['foo']).toBeTruthy();
});
});

0 comments on commit 24eac3d

Please sign in to comment.