Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use hasOwnProperty function rather than built in one. #2475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/graphql-modules/src/di/forward-ref.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { stringify } from './utils';
import { Type } from './providers';
import { hasOwnProperty } from '../shared/utils';

export type ForwardRefFn<T> = () => T;

Expand All @@ -19,7 +20,7 @@ export function forwardRef<T>(forwardRefFn: ForwardRefFn<T>) {
export function resolveForwardRef(type: any): any {
if (
typeof type === 'function' &&
type.hasOwnProperty(forwardRefSymbol) &&
hasOwnProperty(type, forwardRefSymbol) &&
type[forwardRefSymbol] === forwardRef
) {
return (type as ForwardRefFn<any>)();
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql-modules/src/module/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ResolverDuplicatedError,
ResolverInvalidError,
} from './../shared/errors';
import { isNil, isDefined, isPrimitive } from '../shared/utils';
import { isNil, isDefined, isPrimitive, hasOwnProperty } from '../shared/utils';
import {
createMiddleware,
mergeMiddlewareMaps,
Expand Down Expand Up @@ -54,7 +54,7 @@ export function createResolvers(

// Wrap resolvers
for (const typeName in resolvers) {
if (resolvers.hasOwnProperty(typeName)) {
if (hasOwnProperty(resolvers, typeName)) {
const obj = resolvers[typeName];

if (isScalarResolver(obj)) {
Expand All @@ -63,7 +63,7 @@ export function createResolvers(
continue;
} else if (obj && typeof obj === 'object') {
for (const fieldName in obj) {
if (obj.hasOwnProperty(fieldName)) {
if (hasOwnProperty(obj, fieldName)) {
ensure.type(typeName, fieldName);
const path = [typeName, fieldName];

Expand Down Expand Up @@ -215,7 +215,7 @@ function mergeResolvers(config: ModuleConfig): Single<Resolvers> {

for (const currentResolvers of resolvers) {
for (const typeName in currentResolvers) {
if (currentResolvers.hasOwnProperty(typeName)) {
if (hasOwnProperty(currentResolvers, typeName)) {
const value = currentResolvers[typeName];

if (isNil(value)) {
Expand Down Expand Up @@ -255,7 +255,7 @@ function addObject({
}

for (const fieldName in fields) {
if (fields.hasOwnProperty(fieldName)) {
if (hasOwnProperty(fields, fieldName)) {
const resolver = fields[fieldName];

if (isResolveFn(resolver)) {
Expand Down Expand Up @@ -344,7 +344,7 @@ function addEnum({
}

for (const key in resolver) {
if (resolver.hasOwnProperty(key)) {
if (hasOwnProperty(resolver, key)) {
const value = resolver[key];

if (container[typeName][key]) {
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql-modules/src/shared/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GraphQLResolveInfo } from 'graphql';
import { mergeDeepWith } from 'ramda';
import { ModuleMetadata } from './../module/metadata';
import { isDefined } from './utils';
import { hasOwnProperty, isDefined } from './utils';
import { ExtraMiddlewareError, useLocation } from './errors';

export type Next<T = any> = () => Promise<T>;
Expand Down Expand Up @@ -125,7 +125,7 @@ export function validateMiddlewareMap(
const exists = checkExistence(metadata);

for (const typeName in middlewareMap.types) {
if (middlewareMap.types.hasOwnProperty(typeName)) {
if (hasOwnProperty(middlewareMap.types,typeName)) {
const typeMiddlewareMap = middlewareMap[typeName];

if (!exists.type(typeName)) {
Expand All @@ -136,7 +136,7 @@ export function validateMiddlewareMap(
}

for (const fieldName in typeMiddlewareMap[typeName]) {
if (typeMiddlewareMap[typeName].hasOwnProperty(fieldName)) {
if (hasOwnProperty(typeMiddlewareMap[typeName],fieldName)) {
if (!exists.field(typeName, fieldName)) {
throw new ExtraMiddlewareError(
`Cannot apply a middleware to non existing "${typeName}.${fieldName}" type.field`,
Expand Down
4 changes: 4 additions & 0 deletions packages/graphql-modules/src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { GraphQLSchema } from 'graphql';

export function hasOwnProperty(v:unknown, key:PropertyKey){
return Object.prototype.hasOwnProperty.call(v, key);
}

export function flatten<T>(arr: T[]): T extends (infer A)[] ? A[] : T[] {
return Array.prototype.concat(...arr) as any;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-modules/src/testing/test-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { createApplication } from '../application/application';
import { ApplicationConfig } from '../application/types';
import { MockedModule, Module, ModuleConfig } from '../module/types';
import { createModule } from '../module/module';
import { hasOwnProperty } from '../shared/utils';

type TestModuleConfig = {
replaceExtensions?: boolean;
Expand Down Expand Up @@ -429,7 +430,7 @@ function hasPropValue<T extends Record<string, any>, K extends string>(
obj: T,
prop: K
): obj is T {
return Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop];
return hasOwnProperty(obj, prop) && obj[prop];
}

function isRootType(typeName: string) {
Expand Down