GraphQL @mock directive (#5836)

* Add mock directive
* Include tests for @mock directive
This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-07-22 11:19:40 -07:00
committed by Douglas Muraoka
parent f336cc3435
commit 2e0940c996
2 changed files with 43 additions and 0 deletions

View File

@@ -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 };