Skip to content

Commit

Permalink
Remove debugLog
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Jun 17, 2021
1 parent 00c2d8b commit 94b032f
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 144 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-shirts-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': major
---

BREAKING - remove debugLog
6 changes: 4 additions & 2 deletions packages/load/src/filter-document-kind.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { debugLog } from '@graphql-tools/utils';
import { DocumentNode, DefinitionNode, Kind } from 'graphql';
import { env } from 'process';

/**
* @internal
Expand All @@ -18,7 +18,9 @@ export const filterKind = (content: DocumentNode, filterKinds: null | string[])

if (invalidDefinitions.length > 0) {
invalidDefinitions.forEach(d => {
debugLog(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
if (env.DEBUG) {
console.error(`Filtered document of kind ${d.kind} due to filter policy (${filterKinds.join(', ')})`);
}
});
}

Expand Down
11 changes: 8 additions & 3 deletions packages/load/src/load-typedefs/load-file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Source, debugLog } from '@graphql-tools/utils';
import { Source } from '@graphql-tools/utils';
import { env } from 'process';
import { LoadTypedefsOptions } from '../load-typedefs';

export async function loadFile(pointer: string, options: LoadTypedefsOptions): Promise<Source> {
Expand All @@ -17,7 +18,9 @@ export async function loadFile(pointer: string, options: LoadTypedefsOptions): P
return loadedValue;
}
} catch (error) {
debugLog(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
if (env.DEBUG) {
console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
}
throw error;
}
}
Expand All @@ -40,7 +43,9 @@ export function loadFileSync(pointer: string, options: LoadTypedefsOptions): Sou
return loader.loadSync(pointer, options);
}
} catch (error) {
debugLog(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
if (env.DEBUG) {
console.error(`Failed to find any GraphQL type definitions in: ${pointer} - ${error.message}`);
}
throw error;
}
}
Expand Down
11 changes: 7 additions & 4 deletions packages/loaders/code-file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { isSchema, GraphQLSchema, DocumentNode } from 'graphql';
import {
SchemaPointerSingle,
DocumentPointerSingle,
debugLog,
SingleFileOptions,
Source,
UniversalLoader,
Expand All @@ -24,7 +23,7 @@ import isGlob from 'is-glob';
import unixify from 'unixify';
import { tryToLoadFromExport, tryToLoadFromExportSync } from './load-from-module';
import { isAbsolute, resolve } from 'path';
import { cwd } from 'process';
import { cwd, env } from 'process';
import { readFileSync, promises as fsPromises, existsSync } from 'fs';

const { readFile, access } = fsPromises;
Expand Down Expand Up @@ -132,7 +131,9 @@ export class CodeFileLoader implements UniversalLoader<CodeFileLoaderOptions> {
return parseGraphQLSDL(pointer, sdl, options);
}
} catch (e) {
debugLog(`Failed to load schema from code file "${normalizedFilePath}": ${e.message}`);
if (env.DEBUG) {
console.error(`Failed to load schema from code file "${normalizedFilePath}": ${e.message}`);
}
errors.push(e);
}
}
Expand Down Expand Up @@ -175,7 +176,9 @@ export class CodeFileLoader implements UniversalLoader<CodeFileLoaderOptions> {
return parseGraphQLSDL(pointer, sdl, options);
}
} catch (e) {
debugLog(`Failed to load schema from code file "${normalizedFilePath}": ${e.message}`);
if (env.DEBUG) {
console.error(`Failed to load schema from code file "${normalizedFilePath}": ${e.message}`);
}
errors.push(e);
}
}
Expand Down
18 changes: 9 additions & 9 deletions packages/loaders/prisma/src/prisma-yml/Variables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as lodash from 'lodash';
import _ from 'lodash';
// eslint-disable-next-line
// @ts-ignore
import replaceall from 'replaceall';
Expand Down Expand Up @@ -43,18 +43,18 @@ export class Variables {
const deepMapValues = (object: any, callback: any, propertyPath?: string[]): any => {
const deepMapValuesIteratee = (value: any, key: any) =>
deepMapValues(value, callback, propertyPath ? propertyPath.concat(key) : [key]);
if (lodash.isArray(object)) {
return lodash.map(object, deepMapValuesIteratee);
} else if (lodash.isObject(object) && !lodash.isDate(object) && !lodash.isFunction(object)) {
return lodash.extend({}, object, lodash.mapValues(object, deepMapValuesIteratee));
if (_.isArray(object)) {
return _.map(object, deepMapValuesIteratee);
} else if (_.isObject(object) && !_.isDate(object) && !_.isFunction(object)) {
return _.extend({}, object, _.mapValues(object, deepMapValuesIteratee));
}
return callback(object, propertyPath);
};

deepMapValues(objectToPopulate, (property: any, propertyPath: any) => {
if (typeof property === 'string') {
const populateSingleProperty = this.populateProperty(property, true).then((newProperty: any) =>
lodash.set(objectToPopulate, propertyPath, newProperty)
_.set(objectToPopulate, propertyPath, newProperty)
);
populateAll.push(populateSingleProperty);
}
Expand All @@ -64,7 +64,7 @@ export class Variables {
}

populateProperty(propertyParam: any, populateInPlace?: boolean): any {
let property = populateInPlace ? propertyParam : lodash.cloneDeep(propertyParam);
let property = populateInPlace ? propertyParam : _.cloneDeep(propertyParam);
const allValuesToPopulate: any[] = [];
let warned = false;

Expand Down Expand Up @@ -143,7 +143,7 @@ export class Variables {
return (
finalValue !== null &&
typeof finalValue !== 'undefined' &&
!(typeof finalValue === 'object' && lodash.isEmpty(finalValue))
!(typeof finalValue === 'object' && _.isEmpty(finalValue))
);
});
return Promise.resolve(finalValue);
Expand Down Expand Up @@ -214,7 +214,7 @@ export class Variables {
if (
valueToPopulate === null ||
typeof valueToPopulate === 'undefined' ||
(typeof valueToPopulate === 'object' && lodash.isEmpty(valueToPopulate))
(typeof valueToPopulate === 'object' && _.isEmpty(valueToPopulate))
) {
let varType;
if (variableString.match(this.envRefSyntax)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/loaders/prisma/src/prisma-yml/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invert } from 'lodash';
import _ from 'lodash';

export const cloudApiEndpoint = process.env.CLOUD_API_ENDPOINT || 'https://api.cloud.prisma.sh';

Expand All @@ -7,4 +7,4 @@ export const clusterEndpointMap: { [key: string]: string } = {
'prisma-us1': 'https://us1.prisma.sh',
};

export const clusterEndpointMapReverse: { [key: string]: string } = invert(clusterEndpointMap);
export const clusterEndpointMapReverse: { [key: string]: string } = _.invert(clusterEndpointMap);
6 changes: 3 additions & 3 deletions packages/resolvers-composition/src/resolvers-composition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { chainFunctions } from './chain-functions';
import { get, set } from 'lodash';
import _ from 'lodash';
import { GraphQLFieldResolver, GraphQLScalarTypeConfig } from 'graphql';
import { asArray } from '@graphql-tools/utils';

Expand Down Expand Up @@ -127,9 +127,9 @@ export function composeResolvers<Resolvers extends Record<string, any>>(
});

for (const path in mappingResult) {
const fns = chainFunctions([...asArray(mappingResult[path]), () => get(resolvers, path)]);
const fns = chainFunctions([...asArray(mappingResult[path]), () => _.get(resolvers, path)]);

set(resolvers, path, fns());
_.set(resolvers, path, fns());
}

return resolvers;
Expand Down
6 changes: 0 additions & 6 deletions packages/utils/src/debug-log.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/utils/src/getArgumentValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ArgumentNode,
} from 'graphql';

import { inspect } from './inspect';
import { inspect } from 'util';

/**
* Prepares an object map of argument values given a list of argument
Expand Down
1 change: 0 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './loaders';
export * from './helpers';
export * from './debug-log';
export * from './get-directives';
export * from './get-fields-with-directives';
export * from './get-implementing-types';
Expand Down
113 changes: 0 additions & 113 deletions packages/utils/src/inspect.ts

This file was deleted.

0 comments on commit 94b032f

Please sign in to comment.