Skip to content

Commit 567fcee

Browse files
committed
fix test
1 parent ef2aa05 commit 567fcee

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/__tests__.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
const Test = require('tape');
44
const graphql = require('graphql');
55
const gql = require('graphql-tag');
6-
const { SchemaDirectiveVisitor } = require('@graphql-tools/utils');
6+
const { SchemaDirectiveVisitor, MapperKind, mapSchema, getDirective} = require('@graphql-tools/utils');
77
const GraphQLComponent = require('.');
8+
const {defaultFieldResolver} = require("graphql/index");
89

910
Test('GraphQLComponent instance API (getters/setters)', (t) => {
1011

@@ -1109,11 +1110,17 @@ Test(`importing root specifies 'federation: true' results in all components crea
11091110
})
11101111

11111112
Test('federated schema can include custom directive', (t) => {
1112-
class CustomDirective extends SchemaDirectiveVisitor {
1113-
// required for our dummy "custom" directive (ie. implement the SchemaDirectiveVisitor interface)
1114-
visitFieldDefinition() {
1115-
return;
1116-
}
1113+
function customDirective(directiveName) {
1114+
return (schema) => mapSchema(schema, {
1115+
[MapperKind.OBJECT_FIELD]: (fieldConfig) => {
1116+
const directive = getDirective(schema, fieldConfig, directiveName)?.[0]
1117+
if (directive) {
1118+
return {
1119+
...fieldConfig,
1120+
}
1121+
}
1122+
}
1123+
})
11171124
}
11181125

11191126
const component = new GraphQLComponent({
@@ -1142,7 +1149,7 @@ Test('federated schema can include custom directive', (t) => {
11421149
}
11431150
},
11441151
},
1145-
directives: { custom: CustomDirective },
1152+
directives: { custom: customDirective },
11461153
federation: true
11471154
});
11481155

@@ -1163,7 +1170,7 @@ Test('federated schema can include custom directive', (t) => {
11631170
t.plan(2);
11641171
const { schema: { _typeMap: { Extended } } } = component;
11651172
t.equals(Extended.extensionASTNodes.length, 1, 'Extension AST Nodes is defined');
1166-
t.equals(Extended.extensionASTNodes[0].fields.filter((field) => field.name.value === "id" && field.directives[0].name.value === "external").length, 1, `id field marked external`);
1173+
t.equals(Extended.astNode.fields.filter((field) => field.name.value === "id" && field.directives[0].name.value === "external").length, 1, `id field marked external`);
11671174
});
11681175
});
11691176

0 commit comments

Comments
 (0)