defineInspect.js.flow 642 B

123456789101112131415161718192021
  1. // @flow strict
  2. import invariant from './invariant';
  3. import nodejsCustomInspectSymbol from './nodejsCustomInspectSymbol';
  4. /**
  5. * The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
  6. */
  7. export default function defineInspect(
  8. classObject: Class<any> | ((...args: Array<any>) => mixed),
  9. ): void {
  10. const fn = classObject.prototype.toJSON;
  11. invariant(typeof fn === 'function');
  12. classObject.prototype.inspect = fn;
  13. // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
  14. if (nodejsCustomInspectSymbol) {
  15. classObject.prototype[nodejsCustomInspectSymbol] = fn;
  16. }
  17. }