This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
-
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): gql.data module * refactor: graphqlYoga export schame name * chore: update function to handle edge cases * chore: fix lint
- Loading branch information
1 parent
b97038d
commit 9a3d4de
Showing
19 changed files
with
316 additions
and
47 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
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,5 @@ | ||
import { definePergel } from 'pergel' | ||
|
||
export default definePergel({ | ||
|
||
}) |
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,4 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"typescript.enablePromptUseWorkspaceTsdk": true | ||
} |
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,3 @@ | ||
<template> | ||
asdas | ||
</template> |
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,57 @@ | ||
import { resolve } from 'node:path' | ||
import { defineNuxtModule } from '@nuxt/kit' | ||
import { startSubprocess } from '@nuxt/devtools-kit' | ||
|
||
import { DEVTOOLS_UI_PORT } from '../../src/constants' | ||
|
||
export default defineNuxtConfig({ | ||
devtools: { | ||
enabled: true, | ||
}, | ||
modules: [ | ||
/** | ||
* My module | ||
*/ | ||
'../../src/module', | ||
/** | ||
* Start a sub Nuxt Server for developing the client | ||
* | ||
* The terminal output can be found in the Terminals tab of the devtools. | ||
*/ | ||
defineNuxtModule({ | ||
setup(_, nuxt) { | ||
if (!nuxt.options.dev) | ||
return | ||
|
||
const subprocess = startSubprocess( | ||
{ | ||
command: 'npx', | ||
args: ['nuxi', 'dev', '--port', DEVTOOLS_UI_PORT.toString()], | ||
cwd: resolve(__dirname, '../client'), | ||
}, | ||
{ | ||
id: 'nuxt-pergel:client', | ||
name: 'Pergel Devtools RPC Client', | ||
}, | ||
) | ||
|
||
subprocess.getProcess().stdout?.on('data', (data) => { | ||
// eslint-disable-next-line no-console | ||
console.log(` sub: ${data.toString()}`) | ||
}) | ||
|
||
process.on('exit', () => { | ||
subprocess.terminate() | ||
}) | ||
}, | ||
}), | ||
], | ||
pergel: { | ||
debug: true, | ||
projects: { | ||
changeName: { | ||
gqltada: true, | ||
}, | ||
}, | ||
}, | ||
}) |
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,20 @@ | ||
{ | ||
"name": "playground-gqltada", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"dev": "nuxi dev", | ||
"build": "nuxi build", | ||
"prepare": "nuxi prepare", | ||
"generate": "nuxi generate" | ||
}, | ||
"dependencies": { | ||
"gql.tada": "^1.3.1" | ||
}, | ||
"devDependencies": { | ||
"@0no-co/graphqlsp": "^1.4.2", | ||
"@pergel/nuxt": "link:..", | ||
"nuxt": "latest", | ||
"pergel": "^0.12.0" | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/nuxt/playgrounds/gql.tada/server/changeNameSchema.graphql
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,23 @@ | ||
directive @auth on FIELD_DEFINITION | ||
|
||
directive @skipAuth on FIELD_DEFINITION | ||
|
||
|
||
type Query { | ||
me: User | ||
user(id: ID!): User | ||
users: [User] | ||
} | ||
|
||
type Mutation { | ||
changeName(name: String!): User | ||
} | ||
|
||
type User { | ||
id: ID! | ||
name: String! | ||
email: String! | ||
password: String! | ||
createdAt: String! | ||
updatedAt: String! | ||
} |
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,4 @@ | ||
{ | ||
// https://nuxt.com/docs/guide/concepts/typescript | ||
"extends": "./.nuxt/tsconfig.json" | ||
} |
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
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,74 @@ | ||
import { existsSync } from 'node:fs' | ||
import { basename, join, relative, resolve } from 'node:path' | ||
import { camelCase } from 'scule' | ||
import { globbySync } from 'globby' | ||
import { definePergelModule } from '../../core/definePergel' | ||
import { generateProjectReadme } from '../../core/utils/generateYaml' | ||
import { writeFilePergel } from '../../core/utils/writeFilePergel' | ||
import type { GQLTadaOptions, ResolvedGQLTadaOptions } from './types' | ||
|
||
export default definePergelModule<GQLTadaOptions, ResolvedGQLTadaOptions>({ | ||
meta: { | ||
name: 'gqltada', | ||
version: '0.0.1', | ||
dependencies(options, nuxt) { | ||
const deps = nuxt._pergel.pergelPackageJson | ||
return { | ||
'gql.tada': deps['gql.tada'], | ||
} | ||
}, | ||
devDependencies(_options, nuxt) { | ||
const deps = nuxt._pergel.pergelPackageJson | ||
return { | ||
'@0no-co/graphqlsp': deps['@0no-co/graphqlsp'], | ||
} | ||
}, | ||
}, | ||
defaults: { | ||
}, | ||
async setup({ nuxt, options }) { | ||
const { projectName, moduleName } = options | ||
|
||
nuxt.options.typescript.tsConfig ??= {} | ||
nuxt.options.typescript.tsConfig.compilerOptions ??= [] | ||
nuxt.options.typescript.tsConfig.compilerOptions.plugins ??= [] | ||
nuxt.options.typescript.tsConfig.compilerOptions.plugins.push({ | ||
name: '@0no-co/graphqlsp', | ||
schema: relative(nuxt.options.buildDir, join(nuxt.options.serverDir, `${camelCase(`${options.projectName}-schema`)}.graphql`)), | ||
tadaOutputLocation: relative(nuxt.options.buildDir, join(options.rootModuleDir, 'graphql-env.d.ts')), | ||
}) | ||
|
||
if (!existsSync(resolve(options.rootModuleDir, 'index.ts'))) { | ||
const files = globbySync((join(nuxt._pergel.pergelModuleRoot, 'templates', options.moduleName, 'root', '**/*')), { | ||
onlyFiles: true, | ||
}) | ||
|
||
for (const file of files) { | ||
const readFile = await nuxt._pergel.jitiDyanmicImport(file) | ||
if (readFile) { | ||
const fileData = readFile({ | ||
projectName: options.projectName, | ||
nuxt, | ||
}) | ||
const fileName = basename(file) | ||
|
||
writeFilePergel(resolve(options.rootModuleDir, fileName), fileData) | ||
} | ||
} | ||
} | ||
|
||
generateProjectReadme({ | ||
nuxt, | ||
projectName, | ||
moduleName, | ||
data() { | ||
return { | ||
vscode: { | ||
'typescript.tsdk': 'node_modules/typescript/lib', | ||
'typescript.enablePromptUseWorkspaceTsdk': true, | ||
}, | ||
} | ||
}, | ||
}) | ||
}, | ||
}) |
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,5 @@ | ||
export interface GQLTadaOptions { | ||
} | ||
|
||
export interface ResolvedGQLTadaOptions { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { camelCase } from 'scule' | ||
|
||
export default function (data: { | ||
projectName: string | ||
}) { | ||
const graphqlService = camelCase(`${data.projectName}-Graphql`) | ||
|
||
return /* TS */ `import { initGraphQLTada } from 'gql.tada' | ||
import type { | ||
introspection, | ||
} from './graphql-env.d.ts' | ||
export const ${graphqlService} = initGraphQLTada<{ | ||
introspection: introspection | ||
scalars: { | ||
DateTime: string | ||
JSON: any | ||
Cursor: string | ||
ID: string | ||
} | ||
}>() | ||
export type { | ||
FragmentOf, | ||
ResultOf, | ||
VariablesOf, | ||
} from 'gql.tada' | ||
export { readFragment } from 'gql.tada' | ||
` | ||
} |
Oops, something went wrong.