Skip to content

Commit

Permalink
Use reference-equality when filtering rules in buildSchemaFromSDL (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
abernix authored and trevor-scheer committed Oct 2, 2019
1 parent fcdebb9 commit 3a6b11a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- `apollo-env`
- <First `apollo-env` related entry goes here>
- `apollo-graphql`
- <First `apollo-graphql` related entry goes here>
- 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)
- `apollo-language-server`
- Replace old mutation used for checking partial service schemas to use `checkPartialSchema` [#1539](https://github.com/apollographql/apollo-tooling/pull/1539)
- Remove old federation-info provider [#1489](https://github.com/apollographql/apollo-tooling/pull/1489)
Expand Down
15 changes: 11 additions & 4 deletions packages/apollo-graphql/src/schema/buildSchemaFromSDL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ import { isDocumentNode, isNode } from "../utilities/graphql";
import { GraphQLResolverMap } from "./resolverMap";
import { GraphQLSchemaValidationError } from "./GraphQLSchemaValidationError";
import { specifiedSDLRules } from "graphql/validation/specifiedRules";
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 @@ -33,13 +40,13 @@ export interface GraphQLSchemaModule {
}

const skippedSDLRules = [
"PossibleTypeExtensions",
"KnownTypeNames",
"UniqueDirectivesPerLocation"
PossibleTypeExtensions,
KnownTypeNamesRule,
UniqueDirectivesPerLocationRule
];

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

export function modulesFromSDL(
Expand Down

0 comments on commit 3a6b11a

Please sign in to comment.