Repository: graphql/graphql-js
Pull request #3622 (2022-05-31 12:32:59)

fix: update remaining `GraphQLNonNull<GraphQLType>` codepoints to `GraphQLNonNull<GraphQLNullableType>` 
This is related to #3597, in the sense that #3597 made the `GraphQLNonNull<GraphQL*Type>` => `GraphQLNonNull<GraphQLNullable*Type>` change in other code points related to the `isNonNullType` function, but not within `GraphQLWrappingType` or assertNonNullType.

This PR was prompted by the uncovering of a bug by a different PR, see: https://github.com/graphql/graphql-js/pull/3617#discussion_r885544662

netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *compassionate-pike-271cb3* processing.


|  Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | a5213b4f950295a900c962afdb467a36e8cd09b6 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/62960afc1ba587000700b0de |
yaacovCR: We all can and do make mistakes, especially when busy. An extra note explicitly stating that this was a long standing bug could not have hurt, sure.
yaacovCR: I updated the description above. For good measure, I did a quick search for additional code points to correct and udpated the title of this PR.

Patch:
diff --git a/.github/workflows/cmd-publish-pr-on-npm.yml b/.github/workflows/cmd-publish-pr-on-npm.yml
index 66d84d58..115736fa 100644
--- a/.github/workflows/cmd-publish-pr-on-npm.yml
+++ b/.github/workflows/cmd-publish-pr-on-npm.yml
@@ -68,8 +68,8 @@ jobs:
         uses: actions/github-script@v6
         with:
           script: |
-            import fs from 'node:fs';
-            import assert from 'node:assert';
+            const fs = require('node:fs');
+            const assert = require('node:assert');
 
             const pull_request = JSON.parse(process.env.PULL_REQUEST_JSON);
             const packageJSONPath = './npmDist/package.json';
diff --git a/.github/workflows/cmd-run-benchmark.yml b/.github/workflows/cmd-run-benchmark.yml
index 65b858ec..f17e7ed2 100644
--- a/.github/workflows/cmd-run-benchmark.yml
+++ b/.github/workflows/cmd-run-benchmark.yml
@@ -39,7 +39,7 @@ jobs:
         uses: actions/github-script@v6
         with:
           script: |
-            import fs from 'node:fs';
+            const fs = require('node:fs');
 
             // GH doesn't expose job's id so we need to get it through API, see
             // https://github.community/t/job-id-is-string-in-github-job-but-integer-in-actions-api/139060
diff --git a/.github/workflows/github-actions-bot.yml b/.github/workflows/github-actions-bot.yml
index 810cef74..fccdb4eb 100644
--- a/.github/workflows/github-actions-bot.yml
+++ b/.github/workflows/github-actions-bot.yml
@@ -37,7 +37,7 @@ jobs:
         uses: actions/github-script@v6
         with:
           script: |
-            import fs from 'node:fs';
+            const fs = require('node:fs');
 
             const event = JSON.parse(fs.readFileSync('./event.json', 'utf8'));
             await github.rest.issues.createComment({
@@ -110,7 +110,7 @@ jobs:
         uses: actions/github-script@v6
         with:
           script: |
-            import fs from 'node:fs';
+            const fs = require('node:fs');
 
             const needs = JSON.parse(process.env.NEEDS);
 
@@ -134,7 +134,7 @@ jobs:
         uses: actions/github-script@v6
         with:
           script: |
-            import fs from 'node:fs';
+            const fs = require('node:fs');
 
             const replyMessage = fs.readFileSync('./replyMessage.txt', 'utf-8');
             const { issue, comment, sender } = context.payload;
diff --git a/src/type/definition.ts b/src/type/definition.ts
index 9eea02e8..2f9f837c 100644
--- a/src/type/definition.ts
+++ b/src/type/definition.ts
@@ -183,7 +183,9 @@ export function isNonNullType(
   return instanceOf(type, GraphQLNonNull);
 }
 
-export function assertNonNullType(type: unknown): GraphQLNonNull<GraphQLType> {
+export function assertNonNullType(
+  type: unknown,
+): GraphQLNonNull<GraphQLNullableType> {
   if (!isNonNullType(type)) {
     throw new Error(`Expected ${inspect(type)} to be a GraphQL Non-Null type.`);
   }
@@ -395,7 +397,7 @@ export class GraphQLNonNull<T extends GraphQLNullableType> {
 
 export type GraphQLWrappingType =
   | GraphQLList<GraphQLType>
-  | GraphQLNonNull<GraphQLType>;
+  | GraphQLNonNull<GraphQLNullableType>;
 
 export function isWrappingType(type: unknown): type is GraphQLWrappingType {
   return isListType(type) || isNonNullType(type);
diff --git a/src/utilities/extendSchema.ts b/src/utilities/extendSchema.ts
index 998847e9..c451e1e6 100644
--- a/src/utilities/extendSchema.ts
+++ b/src/utilities/extendSchema.ts
@@ -67,6 +67,7 @@ import {
   GraphQLDeprecatedDirective,
   GraphQLDirective,
   GraphQLSpecifiedByDirective,
+  isSpecifiedDirective,
 } from '../type/directives';
 import { introspectionTypes, isIntrospectionType } from '../type/introspection';
 import { isSpecifiedScalarType, specifiedScalarTypes } from '../type/scalars';
@@ -236,6 +237,11 @@ export function extendSchemaImpl(
   }
 
   function replaceDirective(directive: GraphQLDirective): GraphQLDirective {
+    if (isSpecifiedDirective(directive)) {
+      // Builtin directives are not extended.
+      return directive;
+    }
+
     const config = directive.toConfig();
     return new GraphQLDirective({
       ...config,


Test patch:
diff --git a/src/utilities/__tests__/extendSchema-test.ts b/src/utilities/__tests__/extendSchema-test.ts
index 2f4f80e6..c275c023 100644
--- a/src/utilities/__tests__/extendSchema-test.ts
+++ b/src/utilities/__tests__/extendSchema-test.ts
@@ -17,7 +17,7 @@ import {
   assertScalarType,
   assertUnionType,
 } from '../../type/definition';
-import { assertDirective } from '../../type/directives';
+import { assertDirective, specifiedDirectives } from '../../type/directives';
 import {
   GraphQLBoolean,
   GraphQLFloat,
@@ -85,6 +85,34 @@ describe('extendSchema', () => {
     });
   });
 
+  it('Do not modify built-in types and directives', () => {
+    const schema = buildSchema(`
+      type Query {
+        str: String
+        int: Int
+        float: Float
+        id: ID
+        bool: Boolean
+      }
+    `);
+
+    const extensionSDL = dedent`
+      extend type Query {
+        foo: String
+      }
+    `;
+    const extendedSchema = extendSchema(schema, parse(extensionSDL));
+
+    // Built-ins are used
+    expect(extendedSchema.getType('Int')).to.equal(GraphQLInt);
+    expect(extendedSchema.getType('Float')).to.equal(GraphQLFloat);
+    expect(extendedSchema.getType('String')).to.equal(GraphQLString);
+    expect(extendedSchema.getType('Boolean')).to.equal(GraphQLBoolean);
+    expect(extendedSchema.getType('ID')).to.equal(GraphQLID);
+
+    expect(extendedSchema.getDirectives()).to.have.members(specifiedDirectives);
+  });
+
   it('extends objects by adding new fields', () => {
     const schema = buildSchema(`
       type Query {