Skip to content

Commit

Permalink
feat(generate): fix paths injection when automatic generation disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Nov 22, 2023
1 parent cee28e5 commit 0dbbe31
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export default defineNuxtConfig({
queriesDir: 'queries',
// dbschema/ dir (you should not touch this)
queryBuilderDir: 'dbschema/query-builder',
// Toggles typings generation (@db/interfaces)
// Toggles typings generation (#db/interfaces)
generateInterfaces: true,
// Toggles typings generation (@db/queries)
// Toggles typings generation (#db/queries)
generateQueries: true,
// Toggles typings generation (@db/builder)
// Toggles typings generation (#db/builder)
generateQueryBuilder: true,
// Toggles logging messages on code generation
generateQuiet: true,
Expand Down Expand Up @@ -170,11 +170,11 @@ export default defineEventHandler(async (req) => {
})
```

You can still import [queries](https://www.edgedb.com/docs/clients/js/queries) directly from `@db/queries` and pass them the client from `useEdgeDb()`.
You can still import [queries](https://www.edgedb.com/docs/clients/js/queries) directly from `#db/queries` and pass them the client from `useEdgeDb()`.

```typescript
// server/api/blogpost/[id].ts
import { getBlogPost } from '@db/queries'
import { getBlogPost } from '#db/queries'
import { defineEventHandler, getRouterParams } from 'h3'

export default defineEventHandler(async (req) => {
Expand Down
23 changes: 9 additions & 14 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,15 @@ export default defineNuxtModule<ModuleOptions>({
})
}

if (options.generateInterfaces || options.generateQueries || options.generateQueryBuilder) {
const nuxtOptions = nuxt.options

if (options.generateQueries)
nuxtOptions.alias['@db/queries'] = join(dbschemaDir, '/queries.ts')
if (options.generateInterfaces)
nuxtOptions.alias['@db/interfaces'] = join(dbschemaDir, '/interfaces.ts')
if (options.generateQueryBuilder)
nuxtOptions.alias['@db/builder'] = join(dbschemaDir, '/query-builder/index.ts')

await generateInterfaces()
await generateQueries()
await generateQueryBuilder()
}
// Inject aliases
const nuxtOptions = nuxt.options
nuxtOptions.alias['#db/queries'] = join(dbschemaDir, '/queries.ts')
nuxtOptions.alias['#db/interfaces'] = join(dbschemaDir, '/interfaces.ts')
nuxtOptions.alias['#db/builder'] = join(dbschemaDir, '/query-builder/index.ts')

await generateInterfaces()
await generateQueries()
await generateQueryBuilder()

if (options.composables) {
// Add server-side auto-imports
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/useEdgeDbQueries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as queries from '@db/queries'
import type { EventHandlerRequest, H3Event } from 'h3'
import { useEdgeDb } from './useEdgeDb'
import * as queries from '#db/queries'

export function useEdgeDbQueries(
req: H3Event<EventHandlerRequest> | undefined = undefined,
Expand Down

0 comments on commit 0dbbe31

Please sign in to comment.