Skip to content

Commit

Permalink
Conditionally import PossibleTypeExtensions validation rule
Browse files Browse the repository at this point in the history
  • Loading branch information
oguimbal committed May 6, 2020
1 parent 09ac584 commit eba431a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import {
KnownTypeNamesRule,
UniqueDirectivesPerLocationRule
} from "graphql/validation";
// Currently, this PossibleTypeExtensions rule is experimental and thus not
// exposed directly from the rules module above. This may change in the future!
import { PossibleTypeExtensions } from "graphql/validation/rules/PossibleTypeExtensions";
import { mapValues, isNotNullOrUndefined } from "apollo-env";

export interface GraphQLSchemaModule {
Expand All @@ -40,11 +37,22 @@ export interface GraphQLSchemaModule {
}

const skippedSDLRules = [
PossibleTypeExtensions,
KnownTypeNamesRule,
UniqueDirectivesPerLocationRule
];

// Currently, this PossibleTypeExtensions rule is experimental and thus not
// exposed directly from the rules module above. This may change in the future!
// Additionally, it does not exist in prior graphql versions. Thus this try/catch.
try {
const {
PossibleTypeExtensions
} = require("graphql/validation/rules/PossibleTypeExtensions");
skippedSDLRules.push(PossibleTypeExtensions);
} catch (e) {
// ignore this error
}

const sdlRules = specifiedSDLRules.filter(
rule => !skippedSDLRules.includes(rule)
);
Expand Down

0 comments on commit eba431a

Please sign in to comment.