-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): add support for dynamic plugin generation
- Loading branch information
1 parent
e55c093
commit 8e79455
Showing
4 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
packages/nuxt/src/templates/graphqlYoga/drizzle-lucia/root/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/nuxt/src/templates/graphqlYoga/empty/plugins/graphqlv1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { camelCase } from 'scule' | ||
|
||
export default function (data: { | ||
projectName: string | ||
}) { | ||
const pergelFunction = camelCase(`pergel-${data.projectName}`) | ||
const graphQLCreateSchema = camelCase(`${data.projectName}-GraphQLCreateSchema`) | ||
const drizzleStorage = camelCase(`${data.projectName}-Drizzle-Storage`) | ||
const luciaRequest = camelCase(`${data.projectName}-Lucia-Request`) | ||
return /* TS */ `// Please move server/plugins/graphqlv1.ts. If you want to change graphqlv1.ts you can change it. | ||
export default ${pergelFunction}().graphqlYoga().nitro().use({ | ||
onRequest: [ | ||
// If lucia true, remove comment | ||
// ${luciaRequest}, | ||
], | ||
onBeforeOptions: async ({ options }, event) => { | ||
// const allowedOrigins = (propscess.env.ORIGIN as string).split(',') | ||
const origin = event.node.req.headers.origin as string | ||
options.add({ | ||
schema: ${graphQLCreateSchema}, | ||
cors: { | ||
origin, | ||
credentials: true, | ||
}, | ||
}) | ||
}, | ||
async onBeforeContext({ options }, event) { | ||
const db = await ${pergelFunction}().drizzle() | ||
.postgresjs() | ||
.connect({ | ||
event, | ||
}) | ||
const storage = ${drizzleStorage}({ db }) | ||
await options.add({ | ||
db, | ||
storage, | ||
}) | ||
}, | ||
}) | ||
` | ||
} |