summaryrefslogtreecommitdiff
path: root/school/node_modules/graphql/jsutils/defineInspect.js.flow
blob: 5359f76f6b98756794aaead165cb8a8b55bd0d9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// @flow strict
import invariant from './invariant';
import nodejsCustomInspectSymbol from './nodejsCustomInspectSymbol';

/**
 * The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
 */
export default function defineInspect(
  classObject: Class<any> | ((...args: Array<any>) => mixed),
): void {
  const fn = classObject.prototype.toJSON;
  invariant(typeof fn === 'function');

  classObject.prototype.inspect = fn;

  // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
  if (nodejsCustomInspectSymbol) {
    classObject.prototype[nodejsCustomInspectSymbol] = fn;
  }
}