Skip to content

Commit

Permalink
New cross-inspect package
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Oct 30, 2023
1 parent 548ca60 commit accd58f
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-laws-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'cross-inspect': major
---

Cross platform `inspect` implementation similar to Node's `util.inspect`
5 changes: 5 additions & 0 deletions .changeset/modern-teachers-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': patch
---

Extract `inspect` into the new `cross-inspect` package
1 change: 1 addition & 0 deletions packages/executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"value-or-promise": "^1.0.12"
},
"devDependencies": {
"cross-inspect": "0.0.0",
"graphql": "^16.6.0"
},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion packages/executor/src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { inspect } from 'cross-inspect';
import {
GraphQLBoolean,
GraphQLInt,
Expand All @@ -12,7 +14,6 @@ import {
Kind,
parse,
} from 'graphql';
import { inspect } from '@graphql-tools/utils';
import { expectJSON } from '../../__testUtils__/expectJSON.js';
import { execute, executeSync } from '../execute.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/executor/src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { inspect } from 'cross-inspect';
import {
GraphQLArgumentConfig,
GraphQLEnumType,
Expand All @@ -12,7 +14,6 @@ import {
Kind,
parse,
} from 'graphql';
import { inspect } from '@graphql-tools/utils';
import { expectJSON } from '../../__testUtils__/expectJSON.js';
import { executeSync } from '../execute.js';
import { getVariableValues } from '../values.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { inspect } from 'util';
import { inspect } from 'cross-inspect';
import { IResolvers } from '@graphql-tools/utils';

export const typeDefs = readFileSync(join(__dirname, './inventory.graphql'), 'utf8');
Expand Down
61 changes: 61 additions & 0 deletions packages/inspect/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "cross-inspect",
"version": "0.0.0",
"type": "module",
"description": "Cross platform implementation of Node's util.inspect",
"repository": {
"type": "git",
"url": "ardatan/graphql-tools",
"directory": "packages/inspect"
},
"author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
"license": "MIT",
"engines": {
"node": ">=16.0.0"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"exports": {
".": {
"require": {
"types": "./dist/typings/index.d.cts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/typings/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": {
"types": "./dist/typings/*.d.cts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
},
"default": {
"types": "./dist/typings/*.d.ts",
"default": "./dist/esm/*.js"
}
},
"./package.json": "./package.json"
},
"typings": "dist/typings/index.d.ts",
"dependencies": {
"tslib": "^2.4.0"
},
"publishConfig": {
"directory": "dist",
"access": "public"
},
"sideEffects": false,
"typescript": {
"definition": "dist/typings/index.d.ts"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Taken from graphql-js
// https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts

import { GraphQLError } from 'graphql';

const MAX_RECURSIVE_DEPTH = 3;

/**
Expand All @@ -26,7 +23,8 @@ function formatValue(value: unknown, seenValues: ReadonlyArray<unknown>): string
}

function formatError(value: Error): string {
if (value instanceof GraphQLError) {
// eslint-disable-next-line no-constant-condition
if ((value.name = 'GraphQLError')) {
return value.toString();
}
return `${value.name}: ${value.message};\n ${value.stack}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { inspect } from 'cross-inspect';
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
import { loadSchema, loadSchemaSync } from '@graphql-tools/load';
import { inspect } from '@graphql-tools/utils';
import { runTests, useMonorepo } from '../../../../testing/utils.js';

const monorepo = useMonorepo({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { inspect } from 'cross-inspect';
import { GraphQLScalarType, Kind } from 'graphql';
import gql from 'graphql-tag';
import { execute, isIncrementalResult } from '@graphql-tools/executor';
import { makeExecutableSchema } from '@graphql-tools/schema';
import { inspect } from '@graphql-tools/utils';
import { composeResolvers, ResolversComposerMapping } from '../src/index.js';

function createAsyncIterator<T>(array: T[]): AsyncIterator<T, T, T> {
Expand Down
1 change: 1 addition & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"dependencies": {
"@graphql-typed-document-node/core": "^3.1.1",
"cross-inspect": "0.0.0",
"dset": "^3.1.2",
"tslib": "^2.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/astFromType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inspect } from 'cross-inspect';
import { GraphQLType, isListType, isNonNullType, Kind, TypeNode } from 'graphql';
import { inspect } from './inspect.js';

export function astFromType(type: GraphQLType): TypeNode {
if (isNonNullType(type)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/astFromValue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { inspect } from 'cross-inspect';
import {
GraphQLInputType,
isEnumType,
Expand All @@ -10,7 +11,6 @@ import {
ValueNode,
} from 'graphql';
import { astFromValueUntyped } from './astFromValueUntyped.js';
import { inspect } from './inspect.js';
import { isIterableObject, isObjectLike } from './jsutils.js';
import { Maybe } from './types.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/getArgumentValues.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { inspect } from 'cross-inspect';
import {
ArgumentNode,
DirectiveNode,
Expand All @@ -10,7 +11,6 @@ import {
valueFromAST,
} from 'graphql';
import { createGraphQLError } from './errors.js';
import { inspect } from './inspect.js';
import { hasOwnProperty } from './jsutils.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export * from './withCancel.js';
export * from './rootTypes.js';
export * from './comments.js';
export * from './collectFields.js';
export * from './inspect.js';
export { inspect } from 'cross-inspect';
export * from './memoize.js';
export * from './fixSchemaAst.js';
export * from './getOperationASTFromRequest.js';
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"noPropertyAccessFromIndexSignature": true,

"paths": {
"cross-inspect": ["packages/inspect/src/index.ts"],
"@graphql-tools/*-loader": [
"packages/loaders/*/src/index.ts",
"packages/*-loader/src/index.ts"
Expand Down

0 comments on commit accd58f

Please sign in to comment.