UNPKG

851 BJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * strict-local
8 * @format
9 */
10'use strict';
11
12/**
13 * A transform that removes any directives that were not present in the
14 * server schema.
15 */
16function filterDirectivesTransform(context) {
17 return require("./GraphQLIRTransformer").transform(context, {
18 Directive: visitDirective
19 });
20}
21/**
22 * @internal
23 *
24 * Skip directives not defined in the original schema.
25 */
26
27
28function visitDirective(directive) {
29 if (this.getContext().serverSchema.getDirectives().some(function (schemaDirective) {
30 return schemaDirective.name === directive.name;
31 })) {
32 return directive;
33 }
34
35 return null;
36}
37
38module.exports = {
39 transform: filterDirectivesTransform
40};
\No newline at end of file