Skip to content

Commit

Permalink
fix(naming): fix name collisions (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 authored Jan 23, 2019
1 parent 7f22182 commit 871eda0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/schema/SchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class SchemaGenerator {
// This file has been auto-generated by Warthog. Do not update directly as it
// will be re-written. If you need to change this file, update models or add
// new TypeGraphQL objects
import { ArgsType, Field, ID, InputType } from 'type-graphql';
import { ArgsType, Field as TypeGraphQLField, ID, InputType as TypeGraphQLInputType } from 'type-graphql';
import { registerEnumType } from 'type-graphql';
import { BaseWhereInput, PaginationArgs } from '${warthogImportPath}';
${entityListToImports(entities).join('')}
Expand Down
66 changes: 33 additions & 33 deletions src/schema/TypeORMConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ export function entityToWhereUniqueInput(entity: EntityMetadata): string {
const tsType = columnToTypeScriptType(column);

fieldsTemplate += `
@Field(type => ${graphQLDataType}${nullable})
@TypeGraphQLField(type => ${graphQLDataType}${nullable})
${column.propertyName}?: ${tsType};
`;
}
});

const template = `
@InputType()
@TypeGraphQLInputType()
export class ${entity.name}WhereUniqueInput {
${fieldsTemplate}
}
Expand Down Expand Up @@ -112,20 +112,20 @@ export function entityToCreateInput(entity: EntityMetadata): string {

if (column.enum) {
fieldTemplates += `
@Field(type => ${graphQLType}, ${nullable})
@TypeGraphQLField(type => ${graphQLType}, ${nullable})
${column.propertyName}${tsRequired}: ${graphQLType};
`;
} else {
fieldTemplates += `
@Field(${nullable})
@TypeGraphQLField(${nullable})
${column.propertyName}${tsRequired}: ${tsType};
`;
}
}
});

return `
@InputType()
@TypeGraphQLInputType()
export class ${entity.name}CreateInput {
${fieldTemplates}
}
Expand All @@ -151,20 +151,20 @@ export function entityToUpdateInput(entity: EntityMetadata): string {

if (column.enum) {
fieldTemplates += `
@Field(type => ${graphQLType}, { nullable: true })
@TypeGraphQLField(type => ${graphQLType}, { nullable: true })
${column.propertyName}?: ${graphQLType};
`;
} else {
fieldTemplates += `
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}?: ${tsType};
`;
}
}
});

return `
@InputType()
@TypeGraphQLInputType()
export class ${entity.name}UpdateInput {
${fieldTemplates}
}
Expand All @@ -176,8 +176,8 @@ export function entityToUpdateInputArgs(entity: EntityMetadata): string {
return `
@ArgsType()
export class ${entity.name}UpdateArgs {
@Field() data!: ${entity.name}UpdateInput;
@Field() where!: ${entity.name}WhereUniqueInput;
@TypeGraphQLField() data!: ${entity.name}UpdateInput;
@TypeGraphQLField() where!: ${entity.name}WhereUniqueInput;
}
`;
}
Expand All @@ -204,79 +204,79 @@ export function entityToWhereInput(entity: EntityMetadata): string {
// Example: photo.userId: String
if (column.isPrimary || graphqlType === GraphQLID) {
fieldTemplates += `
@Field(type => ${graphqlType},{ nullable: true })
@TypeGraphQLField(type => ${graphqlType},{ nullable: true })
${column.propertyName}_eq?: string;
@Field(type => [${graphqlType}], { nullable: true })
@TypeGraphQLField(type => [${graphqlType}], { nullable: true })
${column.propertyName}_in?: string[];
`;
} else if (graphqlType === GraphQLString) {
// TODO: do we need NOT?
// `${column.propertyName}_not`
fieldTemplates += `
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_eq?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_contains?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_startsWith?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_endsWith?: ${tsType};
@Field(type => [${graphqlType}], { nullable: true })
@TypeGraphQLField(type => [${graphqlType}], { nullable: true })
${column.propertyName}_in?: ${tsType}[];
`;
} else if (graphqlType === GraphQLFloat || graphqlType === GraphQLInt) {
fieldTemplates += `
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_eq?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_gt?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_gte?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_lt?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_lte?: ${tsType};
@Field(type => [${graphqlType}], { nullable: true })
@TypeGraphQLField(type => [${graphqlType}], { nullable: true })
${column.propertyName}_in?: ${tsType}[];
`;
} else if (graphqlType === GraphQLISODateTime) {
fieldTemplates += `
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_gt?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_gte?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_lt?: ${tsType};
@Field({ nullable: true })
@TypeGraphQLField({ nullable: true })
${column.propertyName}_lte?: ${tsType};
`;
} else {
// Enums will fall through here
fieldTemplates += `
@Field(type => ${graphqlType}, { nullable: true })
@TypeGraphQLField(type => ${graphqlType}, { nullable: true })
${column.propertyName}_eq?: ${graphqlType};
@Field(type => [${graphqlType}], { nullable: true })
@TypeGraphQLField(type => [${graphqlType}], { nullable: true })
${column.propertyName}_in?: ${graphqlType}[];
`;
}
});

return `
@InputType()
@TypeGraphQLInputType()
export class ${entity.name}WhereInput extends BaseWhereInput {
${fieldTemplates}
}
Expand All @@ -287,10 +287,10 @@ export function entityToWhereArgs(entity: EntityMetadata): string {
return `
@ArgsType()
export class ${entity.name}WhereArgs extends PaginationArgs {
@Field(type => ${entity.name}WhereInput, { nullable: true })
@TypeGraphQLField(type => ${entity.name}WhereInput, { nullable: true })
where?: ${entity.name}WhereInput;
@Field(type => ${entity.name}OrderByEnum, { nullable: true })
@TypeGraphQLField(type => ${entity.name}OrderByEnum, { nullable: true })
orderBy?: ${entity.name}OrderByEnum;
}
`;
Expand All @@ -302,7 +302,7 @@ export function entityToCreateManyArgs(entity: EntityMetadata): string {
return `
@ArgsType()
export class ${entity.name}CreateManyArgs {
@Field(type => [${entity.name}CreateInput])
@TypeGraphQLField(type => [${entity.name}CreateInput])
data!: ${entity.name}CreateInput[];
}
`;
Expand Down

0 comments on commit 871eda0

Please sign in to comment.