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

Rename graphql export to g #9460

Merged
merged 7 commits into from
Feb 5, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update filter generation script to use g instead of graphql
  • Loading branch information
emmatown authored and dcousens committed Feb 5, 2025
commit 97b0f4507223376bbc00fb53d94c0649bcb233ae
42 changes: 21 additions & 21 deletions prisma-utils/main.ts
Original file line number Diff line number Diff line change
@@ -15,14 +15,14 @@ const SCALARS = ['String', 'Boolean', 'Int', 'Float', 'DateTime', 'Decimal', 'Bi

type Scalar = (typeof SCALARS)[number]
const GRAPHQL_SCALARS = {
String: 'graphql.String',
Boolean: 'graphql.Boolean',
Int: 'graphql.Int',
Float: 'graphql.Float',
Json: 'graphql.JSON',
DateTime: 'graphql.DateTime',
Decimal: 'graphql.Decimal',
BigInt: 'graphql.BigInt',
String: 'g.String',
Boolean: 'g.Boolean',
Int: 'g.Int',
Float: 'g.Float',
Json: 'g.JSON',
DateTime: 'g.DateTime',
Decimal: 'g.Decimal',
BigInt: 'g.BigInt',
} as const

function getSchemaForProvider (provider: Provider) {
@@ -64,24 +64,24 @@ function generateTSType (scalar: Scalar, filter: DMMF.InputType, nesting: boolea
const filterName = filter.name.replace(/Bool/g, 'Boolean')

return [
`type ${filterName}Type = graphql.InputObjectType<{`,
`type ${filterName}Type = g.InputObjectType<{`,
...filter.fields.map(field => {
const suffix = field.isNullable ? ` // can be null` : ``

if (field.name === 'not') {
if (nesting) return ` ${field.name}: graphql.Arg<Nested${filterName}Type>${suffix}`
return ` ${field.name}: graphql.Arg<${filterName}Type>${suffix}`
if (nesting) return ` ${field.name}: g.Arg<Nested${filterName}Type>${suffix}`
return ` ${field.name}: g.Arg<${filterName}Type>${suffix}`
}

if (['in', 'notIn'].includes(field.name)) {
return ` ${field.name}: graphql.Arg<graphql.ListType<graphql.NonNullType<typeof ${gqlType}>>>${suffix}`
return ` ${field.name}: g.Arg<g.ListType<g.NonNullType<typeof ${gqlType}>>>${suffix}`
}

if (field.name === 'mode') {
return ` ${field.name}: graphql.Arg<typeof QueryMode>${suffix}`
return ` ${field.name}: g.Arg<typeof QueryMode>${suffix}`
}

return ` ${field.name}: graphql.Arg<typeof ${gqlType}>${suffix}`
return ` ${field.name}: g.Arg<typeof ${gqlType}>${suffix}`
}),
`}>`,
].join('\n')
@@ -94,28 +94,28 @@ function generateGQLType (scalar: Scalar, filter: DMMF.InputType, nesting: boole
const filterName = filter.name.replace(/Bool/g, 'Boolean')

return [
`const ${filterName}: ${filterName}Type = graphql.inputObject({`,
`const ${filterName}: ${filterName}Type = g.inputObject({`,
` name: '${filterName}',`,
` fields: () => ({`,
...filter.fields.map(field => {
const suffix = field.isNullable ? ` // can be null` : ``

if (field.name === 'mode') {
return ` ${field.name}: graphql.arg({ type: QueryMode }),${suffix}`
return ` ${field.name}: g.arg({ type: QueryMode }),${suffix}`
}

if (field.name === 'not') {
if (nesting) {
return ` ${field.name}: graphql.arg({ type: Nested${filterName} }),${suffix}`
return ` ${field.name}: g.arg({ type: Nested${filterName} }),${suffix}`
}
return ` ${field.name}: graphql.arg({ type: ${filterName} }),${suffix}`
return ` ${field.name}: g.arg({ type: ${filterName} }),${suffix}`
}

if (['in', 'notIn'].includes(field.name)) {
return ` ${field.name}: graphql.arg({ type: graphql.list(graphql.nonNull(${gqlType})) }),${suffix}`
return ` ${field.name}: g.arg({ type: g.list(g.nonNull(${gqlType})) }),${suffix}`
}

return ` ${field.name}: graphql.arg({ type: ${gqlType} }),${suffix}`
return ` ${field.name}: g.arg({ type: ${gqlType} }),${suffix}`
}),
` }),`,
`})`,
@@ -172,7 +172,7 @@ async function generate (provider: Provider) {

return [
`// Do not manually modify this file, it is automatically generated by the package at /prisma-utils in this repo.`,
`import { graphql } from '../../../types/schema'`,
`import { g } from '../../../types/schema'`,

// case sensitivity is only supported for POSTGRES
...(provider === 'postgresql'