Skip to content

Commit

Permalink
inline listTypeInfoName and other loops
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Apr 4, 2024
1 parent 2fae918 commit 722a6b5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 41 deletions.
1 change: 0 additions & 1 deletion examples/custom-output-paths/my-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ type ResolvedPostCreateInput = {
content?: import('./node_modules/.myprisma/client').Prisma.PostCreateInput['content']
publishDate?: import('./node_modules/.myprisma/client').Prisma.PostCreateInput['publishDate']
}

type ResolvedPostUpdateInput = {
id?: undefined
title?: import('./node_modules/.myprisma/client').Prisma.PostUpdateInput['title']
Expand Down
3 changes: 0 additions & 3 deletions examples/extend-graphql-schema-nexus/keystone-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ type ResolvedPostCreateInput = {
publishDate?: import('./node_modules/.myprisma/client').Prisma.PostCreateInput['publishDate']
author?: import('./node_modules/.myprisma/client').Prisma.PostCreateInput['author']
}

type ResolvedPostUpdateInput = {
id?: undefined
title?: import('./node_modules/.myprisma/client').Prisma.PostUpdateInput['title']
Expand All @@ -229,13 +228,11 @@ type ResolvedPostUpdateInput = {
publishDate?: import('./node_modules/.myprisma/client').Prisma.PostUpdateInput['publishDate']
author?: import('./node_modules/.myprisma/client').Prisma.PostUpdateInput['author']
}

type ResolvedAuthorCreateInput = {
id?: import('./node_modules/.myprisma/client').Prisma.AuthorCreateInput['id']
name?: import('./node_modules/.myprisma/client').Prisma.AuthorCreateInput['name']
posts?: import('./node_modules/.myprisma/client').Prisma.AuthorCreateInput['posts']
}

type ResolvedAuthorUpdateInput = {
id?: undefined
name?: import('./node_modules/.myprisma/client').Prisma.AuthorUpdateInput['name']
Expand Down
70 changes: 33 additions & 37 deletions packages/core/src/lib/typescript-schema-printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,42 +186,8 @@ export function printGeneratedTypes (
graphQLSchema: GraphQLSchema,
lists: Record<string, InitialisedList>
) {
const interimCreateUpdateTypes = []
const listsTypeInfo = []
const listsNamespaces = []
prismaClientPath = stringify(prismaClientPath).replace(/'/g, `\\'`)

for (const [listKey, list] of Object.entries(lists)) {
const listTypeInfoName = `Lists.${listKey}.TypeInfo<Session>`

if (list.graphql.isEnabled.create) {
interimCreateUpdateTypes.push(
printInterimType(
prismaClientPath,
list,
listKey,
list.graphql.names.createInputName,
'Create'
)
)
}

if (list.graphql.isEnabled.update) {
interimCreateUpdateTypes.push(
printInterimType(
prismaClientPath,
list,
listKey,
list.graphql.names.updateInputName,
'Update'
)
)
}

listsTypeInfo.push(` readonly ${listKey}: ${listTypeInfoName}`)
listsNamespaces.push(printListTypeInfo(prismaClientPath, listKey, list))
}

return [
'/* eslint-disable */',
'',
Expand All @@ -235,17 +201,47 @@ export function printGeneratedTypes (
Decimal: `import('@keystone-6/core/types').Decimal | string`,
}),
'',
interimCreateUpdateTypes.join('\n\n'),
...(function* () {
for (const [listKey, list] of Object.entries(lists)) {
if (list.graphql.isEnabled.create) {
yield printInterimType(
prismaClientPath,
list,
listKey,
list.graphql.names.createInputName,
'Create'
)
}

if (list.graphql.isEnabled.update) {
yield printInterimType(
prismaClientPath,
list,
listKey,
list.graphql.names.updateInputName,
'Update'
)
}
}
}()),
'',
'export declare namespace Lists {',
...listsNamespaces,
...(function* () {
for (const [listKey, list] of Object.entries(lists)) {
yield printListTypeInfo(prismaClientPath, listKey, list)
}
})(),
'}',
`export type Context<Session = any> = import('@keystone-6/core/types').KeystoneContext<TypeInfo<Session>>`,
`export type Config<Session = any> = import('@keystone-6/core/types').KeystoneConfig<TypeInfo<Session>>`,
'',
'export type TypeInfo<Session = any> = {',
` lists: {`,
...listsTypeInfo,
...(function* () {
for (const listKey in lists) {
yield ` readonly ${listKey}: Lists.${listKey}.TypeInfo<Session>`
}
})(),
` }`,
` prisma: import('${prismaClientPath}').PrismaClient`,
` session: Session`,
Expand Down

0 comments on commit 722a6b5

Please sign in to comment.