Skip to content

Commit

Permalink
fix: Json type changed to Record<string, any>
Browse files Browse the repository at this point in the history
  • Loading branch information
unlight committed Feb 21, 2021
1 parent bd3dd81 commit 2877be7
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 55 deletions.
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}
},
"dependencies": {
"@prisma/generator-helper": "^2.16.0",
"@prisma/generator-helper": "^2.16.1",
"flat": "^5.0.2",
"get-relative-path": "^1.0.2",
"lodash": "^4.17.20",
Expand All @@ -68,10 +68,10 @@
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@nestjs/common": "^7.6.11",
"@nestjs/core": "^7.6.11",
"@nestjs/common": "^7.6.12",
"@nestjs/core": "^7.6.12",
"@nestjs/graphql": "^7.9.8",
"@nestjs/platform-express": "^7.6.11",
"@nestjs/platform-express": "^7.6.12",
"@paljs/plugins": "^2.12.2",
"@prisma/client": "^2.16.0",
"@semantic-release/changelog": "^5.0.1",
Expand All @@ -80,50 +80,50 @@
"@types/flat": "^5.0.1",
"@types/lodash": "^4.14.168",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.25",
"@types/node": "^14.14.27",
"@types/pluralize": "^0.0.29",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"apollo-server-express": "^2.19.2",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0",
"apollo-server-express": "^2.21.0",
"c8": "^7.5.0",
"class-transformer": "^0.3.2",
"class-validator": "^0.13.1",
"commitizen": "^4.2.3",
"cz-customizable": "^6.3.0",
"decimal.js": "^10.2.1",
"eslint": "^7.19.0",
"eslint": "^7.20.0",
"eslint-import-resolver-node": "^0.3.4",
"eslint-plugin-etc": "^1.2.0",
"eslint-plugin-etc": "^1.3.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-only-warn": "^1.0.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-regexp": "^0.1.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sonarjs": "^0.5.0",
"eslint-plugin-sort-class-members": "^1.9.0",
"eslint-plugin-total-functions": "^4.7.2",
"eslint-plugin-unicorn": "^27.0.0",
"eslint-plugin-unicorn": "^28.0.0",
"eslint-plugin-wix-editor": "^3.2.0",
"expect": "^26.6.2",
"find-cache-dir": "^3.3.1",
"git-branch-is": "^4.0.0",
"graphql": "^15.5.0",
"graphql-type-json": "^0.3.2",
"husky": "^4.3.8",
"mocha": "^8.2.1",
"husky": "4",
"mocha": "^8.3.0",
"ololog": "^1.1.164",
"precise-commits": "^1.0.2",
"prettier": "^2.2.1",
"prisma": "^2.16.0",
"prisma": "^2.16.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.6.3",
"semantic-release": "^17.3.7",
"semantic-release": "^17.3.9",
"simplytyped": "^3.3.0",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.1",
"tslib": "^2.1.0",
"typescript": "^4.1.3",
"typescript": "^4.1.5",
"watchexec-bin": "^1.0.0"
}
}
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy-create-many.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class DummyCreateManyInput {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;
}
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy-create.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class DummyCreateInput {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;
}
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy-group-by.output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class DummyGroupBy {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;

@Field(() => DummyCountAggregate, {
nullable: true,
Expand Down
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy-unchecked-create.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class DummyUncheckedCreateInput {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;
}
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy-unchecked-update.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class DummyUncheckedUpdateInput {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;
}
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy-update-many-mutation.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class DummyUpdateManyMutationInput {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;
}
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy-update-many.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class DummyUpdateManyInput {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;
}
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy-update.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class DummyUpdateInput {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;
}
2 changes: 1 addition & 1 deletion src/@generated/dummy/dummy.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export class Dummy {
@Field(() => GraphQLJSON, {
nullable: true,
})
json?: object;
json?: Record<string, any>;
}
4 changes: 2 additions & 2 deletions src/@generated/prisma/json-filter.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export class JsonFilter {
@Field(() => GraphQLJSON, {
nullable: true,
})
equals?: object;
equals?: Record<string, any>;

@Field(() => GraphQLJSON, {
nullable: true,
})
not?: object;
not?: Record<string, any>;
}
4 changes: 2 additions & 2 deletions src/@generated/prisma/json-with-aggregates-filter.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export class JsonWithAggregatesFilter {
@Field(() => GraphQLJSON, {
nullable: true,
})
equals?: object;
equals?: Record<string, any>;

@Field(() => GraphQLJSON, {
nullable: true,
})
not?: object;
not?: Record<string, any>;

@Field(() => IntFilter, {
nullable: true,
Expand Down
4 changes: 1 addition & 3 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ export async function generate(args: GenerateArgs) {
}
// Generate output types
const outputTypes = prismaClientDmmf.schema.outputObjectTypes.prisma.filter(
t =>
!['Query', 'Mutation'].includes(t.name) &&
!models.some(name => name === t.name),
t => !['Query', 'Mutation'].includes(t.name) && !models.includes(t.name),
);
for (const outputType of outputTypes) {
const name = getOutputTypeName(outputType.name);
Expand Down
5 changes: 3 additions & 2 deletions src/mutate-filters/rename-zoo-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { renameInputs } from './rename-inputs';

export function replacementTypeName(name: string) {
name = name
.replace('CreateNestedMany', 'CreateMany')
.replace('UncheckedCreateNestedMany', 'CreateMany')
.replace('UncheckedCreateMany', 'CreateMany')
.replace('UpdateNestedMany', 'UpdateMany')
.replace('UncheckedUpdateMany', 'UpdateMany')
.replace('CreateNestedMany', 'CreateMany')
.replace('UpdateNestedMany', 'UpdateMany')
.replace('CreateNestedOne', 'CreateOne')
.replace('InputEnvelope', 'EnvelopeInput');

Expand Down
11 changes: 3 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createConfig } from './utils';

export { DMMF as PrismaDMMF } from '@prisma/client/runtime';

export type TypeRecord = Partial<{
Expand All @@ -7,11 +9,4 @@ export type TypeRecord = Partial<{
graphqlModule: string;
}>;

export type GeneratorConfiguration = {
outputFilePattern: string;
combineScalarFilters: boolean;
atomicNumberOperations: boolean;
types: Record<string, TypeRecord>;
reExportAll: boolean;
renameZooTypes: boolean;
};
export type GeneratorConfiguration = ReturnType<typeof createConfig>;
24 changes: 13 additions & 11 deletions src/utils/create-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { unflatten } from 'flat';
import { merge } from 'lodash';
import { Nullable } from 'simplytyped';

import { GeneratorConfiguration, TypeRecord } from '../types';
import { TypeRecord } from '../types';

export function createConfig(
data: Record<string, string | undefined>,
): GeneratorConfiguration {
export function createConfig(data: Record<string, string | undefined>) {
const config = merge({}, unflatten(data, { delimiter: '_' })) as Record<
string,
unknown
Expand All @@ -21,13 +19,17 @@ export function createConfig(
atomicNumberOperations: ['true', '1', 'on'].includes(
(config.atomicNumberOperations as Nullable<string>) ?? 'false',
),
types: merge(config.types || {}, {
Json: {
fieldType: 'object',
graphqlType: 'GraphQLJSON',
graphqlModule: 'graphql-type-json',
} as TypeRecord,
}),
types: merge(
{},
{
Json: {
fieldType: 'Record<string, any>',
graphqlType: 'GraphQLJSON',
graphqlModule: 'graphql-type-json',
},
},
config.types,
) as Record<string, TypeRecord>,
reExportAll: ['true', '1', 'on'].includes(
(config.reExportAll as Nullable<string>) ?? 'false',
),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const patterns = new Map<PatternKey, PatternValue>([
[{ type: type => type === 'Float', kind: 'scalar' }, () => 'number'],
[{ type: type => type === 'Int', kind: 'scalar' }, () => 'number'],
[{ type: type => type === 'Boolean', kind: 'scalar' }, () => 'boolean'],
[{ type: type => type === 'Json', kind: 'scalar' }, () => 'object'],
[{ type: type => type === 'Json', kind: 'scalar' }, () => 'any'],
[{ type: type => type === 'Null', kind: 'scalar' }, () => 'null'],
[{ type: type => type === 'Decimal', kind: 'scalar' }, () => 'string'],
[{ type: type => type === 'Bytes', kind: 'scalar' }, () => 'Buffer'],
Expand Down

0 comments on commit 2877be7

Please sign in to comment.