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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct type safety issues and typos in entities.ts #2672

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/utils/src/graphql/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function getAllEntitiesRelations(_schema: GraphQLSchema | string | null):
return resolveName(type.type);
default:
// Any case in case future adds new kind
throw new Error(`Unandled node kind: ${(type as any).kind}`);
throw new Error(`Unhandled node kind: ${(type as any).kind}`);
}
};

Expand Down Expand Up @@ -326,26 +326,26 @@ function getJoinIndexFields(
entity: GraphQLObjectType<any, any>,
entityFields: GraphQLField<any, any, {[p: string]: any}>[],
fkNameSet: string[],
IndexArgFields: string[]
indexArgFields: string[]
): string[] {
if (IndexArgFields.length === 1) {
logger.warn(`Composite index expected to be more than 1 field , entity ${entity} [${IndexArgFields}]`);
if (indexArgFields.length === 1) {
logger.warn(`Composite index expected to be more than 1 field , entity ${entity} [${indexArgFields}]`);
}
if (IndexArgFields.length > 3) {
if (indexArgFields.length > 3) {
throw new Error(
`Composite index on entity ${entity} expected not more than 3 fields, index [${IndexArgFields}] got ${IndexArgFields.length} fields`
`Composite index on entity ${entity} expected not more than 3 fields, index [${indexArgFields}] got ${indexArgFields.length} fields`
);
}
// check duplicate fields
const duplicateFields = IndexArgFields.filter((name, index, arr) => arr.indexOf(name) !== index);
const duplicateFields = indexArgFields.filter((name, index, arr) => arr.indexOf(name) !== index);
if (duplicateFields.length) {
throw new Error(`Composite index ${entity}.${IndexArgFields} got duplicated fields: ${duplicateFields}`);
throw new Error(`Composite index ${entity}.${indexArgFields} got duplicated fields: ${duplicateFields}`);
}
return IndexArgFields.map((j) => {
return indexArgFields.map((j) => {
const fieldInEntity = entityFields.find((f) => f.name === j);
// check whether these fields are exist in the entity
if (fieldInEntity === undefined) {
throw new Error(`Composite index [${IndexArgFields}], field ${j} not found within entity ${entity} `);
throw new Error(`Composite index [${indexArgFields}], field ${j} not found within entity ${entity} `);
}
// check is fk
if (fkNameSet.includes(fieldInEntity.name)) {
Expand Down