GraphQL @mock directive (#5836)
* Add mock directive * Include tests for @mock directive
This commit is contained in:
committed by
Douglas Muraoka
parent
f336cc3435
commit
2e0940c996
@@ -5,6 +5,7 @@ import { FunctionsRouter } from '../../Routers/FunctionsRouter';
|
||||
export const definitions = gql`
|
||||
directive @namespace on FIELD_DEFINITION
|
||||
directive @resolve(to: String) on FIELD_DEFINITION
|
||||
directive @mock(with: Any!) on FIELD_DEFINITION
|
||||
`;
|
||||
|
||||
const load = parseGraphQLSchema => {
|
||||
@@ -46,6 +47,16 @@ const load = parseGraphQLSchema => {
|
||||
}
|
||||
|
||||
parseGraphQLSchema.graphQLSchemaDirectives.resolve = ResolveDirectiveVisitor;
|
||||
|
||||
class MockDirectiveVisitor extends SchemaDirectiveVisitor {
|
||||
visitFieldDefinition(field) {
|
||||
field.resolve = () => {
|
||||
return this.args.with;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
parseGraphQLSchema.graphQLSchemaDirectives.mock = MockDirectiveVisitor;
|
||||
};
|
||||
|
||||
export { load };
|
||||
|
||||
Reference in New Issue
Block a user