Skip to content

Commit 3a6b11a

Browse files
abernixtrevor-scheer
authored andcommitted
Use reference-equality when filtering rules in buildSchemaFromSDL (#1551)
Use object equality when filtering rules in `buildSchemaFromSDL` Similar in spirit to apollographql/apollo-server#3338. The technique previously used for removing rules from the standard `specifiedRules` was leveraging a check on `Function.prototype.name`, rather than doing direct object equality. While that does generally work, thanks to the more recent standardization of `Function.prototype.name`, it still breaks down under some of the more aggressive minification techniques since a function's name is not guaranteed to remain the same. Fixes: apollographql/apollo-server#3335
1 parent fcdebb9 commit 3a6b11a

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- `apollo-env`
2121
- <First `apollo-env` related entry goes here>
2222
- `apollo-graphql`
23-
- <First `apollo-graphql` related entry goes here>
23+
- Use reference-equality, rather than `Function.prototype.name` string comparison, when omitting validation rules within `buildSchemaFromSDL`. [#1551](https://github.com/apollographql/apollo-tooling/pull/1551)
2424
- `apollo-language-server`
2525
- Replace old mutation used for checking partial service schemas to use `checkPartialSchema` [#1539](https://github.com/apollographql/apollo-tooling/pull/1539)
2626
- Remove old federation-info provider [#1489](https://github.com/apollographql/apollo-tooling/pull/1489)

packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ import { isDocumentNode, isNode } from "../utilities/graphql";
2525
import { GraphQLResolverMap } from "./resolverMap";
2626
import { GraphQLSchemaValidationError } from "./GraphQLSchemaValidationError";
2727
import { specifiedSDLRules } from "graphql/validation/specifiedRules";
28+
import {
29+
KnownTypeNamesRule,
30+
UniqueDirectivesPerLocationRule
31+
} from "graphql/validation";
32+
// Currently, this PossibleTypeExtensions rule is experimental and thus not
33+
// exposed directly from the rules module above. This may change in the future!
34+
import { PossibleTypeExtensions } from "graphql/validation/rules/PossibleTypeExtensions";
2835
import { mapValues, isNotNullOrUndefined } from "apollo-env";
2936

3037
export interface GraphQLSchemaModule {
@@ -33,13 +40,13 @@ export interface GraphQLSchemaModule {
3340
}
3441

3542
const skippedSDLRules = [
36-
"PossibleTypeExtensions",
37-
"KnownTypeNames",
38-
"UniqueDirectivesPerLocation"
43+
PossibleTypeExtensions,
44+
KnownTypeNamesRule,
45+
UniqueDirectivesPerLocationRule
3946
];
4047

4148
const sdlRules = specifiedSDLRules.filter(
42-
rule => !skippedSDLRules.includes(rule.name)
49+
rule => !skippedSDLRules.includes(rule)
4350
);
4451

4552
export function modulesFromSDL(

0 commit comments

Comments
 (0)