Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/jolly-drinks-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@graphql-tools/utils': patch
---

Use `specifiedDirectives.some` instead of `isSpecifiedDirective` to check if the directive is a
native directive

In case of overriding a native directive like `@deprecated`, `isSpecifiedDirective` only checks the name like;

```ts
isSpecifiedDirective(directive) {
return specifiedDirectives.some(specifiedDirective => directive.name === specifiedDirective.name);
}
```

But we need to check the actual reference equality to avoid rewiring native directives like below;

```ts
specifiedDirectives.some(specifiedDirective => directive === specifiedDirective)
```
27 changes: 27 additions & 0 deletions packages/schema/tests/reproductions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { stripIgnoredCharacters } from 'graphql';
import { printSchemaWithDirectives } from '@graphql-tools/utils';
import { makeExecutableSchema } from '../src/makeExecutableSchema';

test('works', () => {
const typeDefs = stripIgnoredCharacters(/* GraphQL */ `
schema {
query: Query
}

directive @deprecated(
owner: String!
expiry: Date!
reason: String!
) on FIELD_DEFINITION | INPUT_FIELD_DEFINITION

scalar Date

type Query {
myField: String! @deprecated(owner: "Test Squad", expiry: "2025-12-31", reason: "test")
}
`);
const schema = makeExecutableSchema({
typeDefs,
});
expect(stripIgnoredCharacters(printSchemaWithDirectives(schema))).toBe(typeDefs);
});
1 change: 0 additions & 1 deletion packages/utils/src/mapSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export function mapSchema(schema: GraphQLSchema, schemaMapper: SchemaMapper = {}
const newDirectives = mapDirectives(originalDirectives, schema, schemaMapper);

const { typeMap, directives } = rewireTypes(newTypeMap, newDirectives);

return new GraphQLSchema({
...schema.toConfig(),
query: getObjectTypeFromTypeMap(
Expand Down
3 changes: 1 addition & 2 deletions packages/utils/src/print-schema-with-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
isIntrospectionType,
isObjectType,
isScalarType,
isSpecifiedDirective,
isSpecifiedScalarType,
isUnionType,
Kind,
Expand Down Expand Up @@ -75,7 +74,7 @@ export function getDocumentNodeFromSchema(

const directives = schema.getDirectives();
for (const directive of directives) {
if (isSpecifiedDirective(directive)) {
if (specifiedDirectives.some(specifiedDirective => specifiedDirective === directive)) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/rewire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
isNonNullType,
isObjectType,
isScalarType,
isSpecifiedDirective,
isSpecifiedScalarType,
isUnionType,
specifiedDirectives,
} from 'graphql';
import { getBuiltInForStub, isNamedStub } from './stub.js';

Expand Down Expand Up @@ -74,7 +74,7 @@ export function rewireTypes(
};

function rewireDirective(directive: GraphQLDirective): GraphQLDirective {
if (isSpecifiedDirective(directive)) {
if (specifiedDirectives.some(specifiedDirective => specifiedDirective === directive)) {
return directive;
}
const directiveConfig = directive.toConfig();
Expand Down
Loading