UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

59 lines (48 loc) 1.85 kB
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } /** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * */ import nodejsCustomInspectSymbol from './nodejsCustomInspectSymbol'; /** * Used to print values in error messages. */ export default function inspect(value) { switch (_typeof(value)) { case 'string': return JSON.stringify(value); case 'function': return value.name ? "[function ".concat(value.name, "]") : '[function]'; case 'object': if (value) { var customInspectFn = getCustomFn(value); if (customInspectFn) { // $FlowFixMe(>=0.90.0) var customValue = customInspectFn.call(value); return typeof customValue === 'string' ? customValue : inspect(customValue); } else if (Array.isArray(value)) { return '[' + value.map(inspect).join(', ') + ']'; } var properties = Object.keys(value).map(function (k) { return "".concat(k, ": ").concat(inspect(value[k])); }).join(', '); return properties ? '{ ' + properties + ' }' : '{}'; } return String(value); default: return String(value); } } function getCustomFn(object) { var customInspectFn = object[String(nodejsCustomInspectSymbol)]; if (typeof customInspectFn === 'function') { return customInspectFn; } if (typeof object.inspect === 'function') { return object.inspect; } }