nitro-graphql 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,17 +36,30 @@
36
36
 
37
37
  ### Step 1: Installation
38
38
 
39
- Choose your preferred package manager:
39
+ Choose your GraphQL framework and install required dependencies:
40
40
 
41
+ **For GraphQL Yoga:**
41
42
  ```bash
42
43
  # npm
43
- npm install nitro-graphql
44
+ npm install nitro-graphql graphql-yoga graphql
44
45
 
45
46
  # pnpm (recommended)
46
- pnpm add nitro-graphql
47
+ pnpm add nitro-graphql graphql-yoga graphql
47
48
 
48
49
  # yarn
49
- yarn add nitro-graphql
50
+ yarn add nitro-graphql graphql-yoga graphql
51
+ ```
52
+
53
+ **For Apollo Server:**
54
+ ```bash
55
+ # npm
56
+ npm install nitro-graphql @apollo/server graphql
57
+
58
+ # pnpm (recommended)
59
+ pnpm add nitro-graphql @apollo/server graphql
60
+
61
+ # yarn
62
+ yarn add nitro-graphql @apollo/server graphql
50
63
  ```
51
64
 
52
65
  ### Step 2: Setup Your Project
@@ -112,7 +125,9 @@ type Query {
112
125
  greeting(name: String!): String!
113
126
  }
114
127
 
115
- type Mutation
128
+ type Mutation {
129
+ _empty: String
130
+ }
116
131
  ```
117
132
 
118
133
  ### Step 4: Create Your First Resolver
@@ -176,6 +191,7 @@ server/
176
191
  │ │ ├── post-queries.resolver.ts # Post query resolvers (use named exports)
177
192
  │ │ └── create-post.resolver.ts # Post mutation resolvers (use named exports)
178
193
  │ └── config.ts # Optional GraphQL configuration
194
+ │ └── schema.ts # Changing Special Return types
179
195
  ```
180
196
 
181
197
  > [!TIP]
@@ -321,6 +337,52 @@ The module automatically generates TypeScript types for you:
321
337
 
322
338
  Your IDE will automatically provide type safety and autocomplete!
323
339
 
340
+ #### Using Generated Types
341
+
342
+ You can import and use the generated types in your code:
343
+
344
+ **Client-side types** (`#graphql/client`):
345
+ ```ts
346
+ // Import generated types for queries, mutations, and operations
347
+ import type { GetUsersQuery, CreateUserInput } from '#graphql/client'
348
+
349
+ // Use in Vue components
350
+ const users = ref<GetUsersQuery['users']>([])
351
+
352
+ // Use in composables
353
+ export function useUsers() {
354
+ const createUser = async (input: CreateUserInput) => {
355
+ // Type-safe input
356
+ }
357
+ }
358
+ ```
359
+
360
+ **Server-side types** (`#graphql/server`):
361
+ ```ts
362
+ // Import generated types and interfaces
363
+ import type { User, Post, CreateUserInput } from '#graphql/server'
364
+
365
+ // Use types in your server code
366
+ function validateUser(user: User): boolean {
367
+ return user.email.includes('@')
368
+ }
369
+
370
+ // Use in data layer
371
+ async function getUserPosts(user: User): Promise<Post[]> {
372
+ // user is fully typed with all fields
373
+ return await db.posts.findMany({ where: { authorId: user.id } })
374
+ }
375
+
376
+ // Use input types for validation
377
+ function validateCreateUserInput(input: CreateUserInput): void {
378
+ if (!input.email || !input.name) {
379
+ throw new Error('Email and name are required')
380
+ }
381
+ }
382
+ ```
383
+
384
+ These imports provide full TypeScript support with autocompletion, type checking, and IntelliSense in your IDE.
385
+
324
386
  > [!TIP]
325
387
  > **Nitro Auto-Imports**: Thanks to Nitro's auto-import feature, you don't need to manually import `defineResolver`, `defineQuery`, `defineMutation`, and other utilities in your resolver files. They're available globally! However, if you prefer explicit imports, you can use:
326
388
  > ```ts
@@ -560,6 +622,7 @@ export const postTypes = defineType({
560
622
  You can override schema types if needed. StandardSchema supported — Zod, Valibot, anything works:
561
623
 
562
624
  ```ts
625
+ # server/graphql/schema.ts
563
626
  import { defineSchema } from 'nitro-graphql/utils/define'
564
627
  import { z } from 'zod'
565
628
 
@@ -1007,6 +1070,53 @@ const client = createGraphQLClient({
1007
1070
  > [!IMPORTANT]
1008
1071
  > Please don't forget to read the [Contribution Guidelines](CONTRIBUTING.md) document before contributing.
1009
1072
 
1073
+ ## 📋 Community TODOs
1074
+
1075
+ Help us improve nitro-graphql! Pick any item and contribute:
1076
+
1077
+ ### 🚀 Framework Examples
1078
+ - [ ] Nitro-compatible framework integrations
1079
+ - [ ] Nuxt + Pinia Colada example
1080
+ - [ ] StackBlitz playground demos
1081
+
1082
+ ### 🧹 Code Quality
1083
+ - [ ] Performance benchmarks
1084
+ - [ ] Bundle size optimization
1085
+ - [ ] Testing utilities
1086
+ - [ ] Error handling patterns
1087
+
1088
+ ### 📚 Documentation
1089
+ - [ ] Video tutorials
1090
+ - [ ] Migration guides
1091
+ - [ ] Best practices guide
1092
+
1093
+ ### 🔧 Developer Tools
1094
+ - [ ] VS Code extension
1095
+ - [ ] CLI tools
1096
+ - [ ] Debug utilities
1097
+
1098
+ ### 🌐 Integrations
1099
+ - [ ] Database adapters (Prisma, Drizzle)
1100
+ - [ ] Cache strategies
1101
+ - [ ] Deployment guides
1102
+
1103
+ > [!NOTE]
1104
+ > Have other ideas? Open an issue to discuss!
1105
+
1106
+ ## 🛠️ VS Code Extensions
1107
+
1108
+ For the best development experience with GraphQL, install these recommended VS Code extensions:
1109
+
1110
+ - **[GraphQL: Language Feature Support](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql)** - Provides GraphQL language features like autocompletion, go-to definition, and schema validation
1111
+ - **[GraphQL: Syntax Highlighting](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql-syntax)** - Adds syntax highlighting for GraphQL queries, mutations, subscriptions, and schema files
1112
+
1113
+ These extensions will enable:
1114
+ - 🎨 Syntax highlighting for `.graphql` files
1115
+ - 📝 IntelliSense and autocompletion based on your schema
1116
+ - ✅ Real-time validation of GraphQL queries
1117
+ - 🔍 Go-to definition for types and fields
1118
+ - 💡 Hover information for GraphQL elements
1119
+
1010
1120
  ---
1011
1121
 
1012
1122
  ### 🌟 Thank You
@@ -1,7 +1,7 @@
1
- import * as _nuxt_schema7 from "@nuxt/schema";
1
+ import * as _nuxt_schema4 from "@nuxt/schema";
2
2
 
3
3
  //#region src/ecosystem/nuxt.d.ts
4
4
  interface ModuleOptions {}
5
- declare const _default: _nuxt_schema7.NuxtModule<ModuleOptions, ModuleOptions, false>;
5
+ declare const _default: _nuxt_schema4.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
  //#endregion
7
7
  export { ModuleOptions, _default as default };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { StandardSchemaV1 } from "./types/standard-schema.js";
2
2
  import { CodegenClientConfig, CodegenServerConfig, GenImport, NitroGraphQLOptions } from "./types/index.js";
3
- import * as nitropack2 from "nitropack";
3
+ import * as nitropack5 from "nitropack";
4
4
 
5
5
  //#region src/index.d.ts
6
6
  type GraphQLFramework = 'graphql-yoga';
7
- declare const _default: nitropack2.NitroModule;
7
+ declare const _default: nitropack5.NitroModule;
8
8
  //#endregion
9
9
  export { CodegenClientConfig, CodegenServerConfig, GenImport, GraphQLFramework, NitroGraphQLOptions, StandardSchemaV1, _default as default };
package/dist/index.js CHANGED
@@ -128,7 +128,7 @@ var src_default = defineNitroModule({
128
128
  return void 0;
129
129
  };
130
130
  rollupConfig$1.output.chunkFileNames = (chunkInfo) => {
131
- if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.includes("/graphql/") || id.includes(".graphql") || id.includes(".resolver.ts") || id.includes(".gql"))) return `chunks/graphql/[name].mjs`;
131
+ if (chunkInfo.moduleIds && chunkInfo.moduleIds.some((id) => id.endsWith(".graphql") || id.endsWith(".resolver.ts") || id.endsWith(".gql"))) return `chunks/graphql/[name].mjs`;
132
132
  if (typeof chunkFiles === "function") return chunkFiles(chunkInfo);
133
133
  return `chunks/_/[name].mjs`;
134
134
  };
@@ -149,7 +149,7 @@ declare module 'nitro-graphql' {
149
149
  types.tsConfig.compilerOptions.paths ??= {};
150
150
  types.tsConfig.compilerOptions.paths["#graphql/server"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts"))];
151
151
  types.tsConfig.compilerOptions.paths["#graphql/client"] = [relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts"))];
152
- types.tsConfig.compilerOptions.paths["#graphql/schemas"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schemas.ts"))];
152
+ types.tsConfig.compilerOptions.paths["#graphql/schema"] = [relativeWithDot(tsconfigDir, join(nitro.graphql.serverDir, "schema.ts"))];
153
153
  types.tsConfig.include = types.tsConfig.include || [];
154
154
  types.tsConfig.include.push(relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-server.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "nitro-graphql-client.d.ts")), relativeWithDot(tsconfigDir, join(typesDir, "graphql.d.ts")));
155
155
  });
package/dist/rollup.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { getImportId, scanGraphql } from "./utils/index.js";
2
2
  import { serverTypeGeneration } from "./utils/server-type-generation.js";
3
+ import { resolve } from "pathe";
3
4
  import { readFile } from "node:fs/promises";
4
5
  import { parse } from "graphql";
5
6
  import { genImport } from "knitwork";
@@ -8,6 +9,7 @@ import { genImport } from "knitwork";
8
9
  async function rollupConfig(app) {
9
10
  virtualDefs(app);
10
11
  virtualResolvers(app);
12
+ getGraphQLConfig(app);
11
13
  app.hooks.hook("rollup:before", (nitro, rollupConfig$1) => {
12
14
  rollupConfig$1.plugins = rollupConfig$1.plugins || [];
13
15
  const { include = /\.(graphql|gql)$/i, exclude, validate = false } = app.options.graphql?.loader || {};
@@ -82,6 +84,16 @@ function virtualResolvers(app) {
82
84
  return code;
83
85
  };
84
86
  }
87
+ function getGraphQLConfig(app) {
88
+ const configPath = resolve(app.graphql.serverDir, "config.ts");
89
+ app.options.virtual ??= {};
90
+ app.options.virtual["#nitro-internal-virtual/graphql-config"] = () => {
91
+ return `import config from '${configPath}'
92
+ const importedConfig = config
93
+ export { importedConfig }
94
+ `;
95
+ };
96
+ }
85
97
 
86
98
  //#endregion
87
99
  export { rollupConfig };
@@ -1,6 +1,6 @@
1
- import * as h35 from "h3";
1
+ import * as h32 from "h3";
2
2
 
3
3
  //#region src/routes/apollo-server.d.ts
4
- declare const _default: h35.EventHandler<h35.EventHandlerRequest, any>;
4
+ declare const _default: h32.EventHandler<h32.EventHandlerRequest, any>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,5 +1,7 @@
1
1
  import { startServerAndCreateH3Handler } from "../utils/apollo.js";
2
+ import defu from "defu";
2
3
  import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
4
+ import { importedConfig } from "#nitro-internal-virtual/graphql-config";
3
5
  import { defs } from "#nitro-internal-virtual/server-defs";
4
6
  import { resolvers } from "#nitro-internal-virtual/server-resolvers";
5
7
  import { ApolloServer } from "@apollo/server";
@@ -24,12 +26,12 @@ let apolloServer;
24
26
  function createApolloServer() {
25
27
  if (!apolloServer) {
26
28
  const { typeDefs, resolvers: mergedResolvers } = createMergedSchema();
27
- apolloServer = new ApolloServer({
29
+ apolloServer = new ApolloServer(defu({
28
30
  typeDefs,
29
31
  resolvers: mergedResolvers,
30
32
  introspection: true,
31
33
  plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })]
32
- });
34
+ }, importedConfig));
33
35
  }
34
36
  return apolloServer;
35
37
  }
@@ -1,4 +1,6 @@
1
+ import defu from "defu";
1
2
  import { mergeResolvers, mergeTypeDefs } from "@graphql-tools/merge";
3
+ import { importedConfig } from "#nitro-internal-virtual/graphql-config";
2
4
  import { defs } from "#nitro-internal-virtual/server-defs";
3
5
  import { resolvers } from "#nitro-internal-virtual/server-resolvers";
4
6
  import { defineEventHandler, toWebRequest } from "h3";
@@ -40,12 +42,12 @@ let yoga;
40
42
  var graphql_yoga_default = defineEventHandler(async (event) => {
41
43
  if (!yoga) {
42
44
  const schema = createMergedSchema();
43
- yoga = createYoga({
45
+ yoga = createYoga(defu({
44
46
  schema,
45
47
  graphqlEndpoint: "/api/graphql",
46
48
  landingPage: false,
47
49
  renderGraphiQL: () => apolloSandboxHtml
48
- });
50
+ }, importedConfig));
49
51
  }
50
52
  const request = toWebRequest(event);
51
53
  const response = await yoga.handleRequest(request, event);
@@ -1,7 +1,7 @@
1
- import * as h33 from "h3";
1
+ import * as h36 from "h3";
2
2
 
3
3
  //#region src/routes/health.d.ts
4
- declare const _default: h33.EventHandler<h33.EventHandlerRequest, Promise<{
4
+ declare const _default: h36.EventHandler<h36.EventHandlerRequest, Promise<{
5
5
  status: string;
6
6
  message: string;
7
7
  timestamp: string;
@@ -55,7 +55,7 @@ async function generateTypes(schema, config = {}, outputPath) {
55
55
  imports: { plugin: () => {
56
56
  return {
57
57
  prepend: [
58
- `import schemas from '#graphql/schemas'`,
58
+ `import schemas from '#graphql/schema'`,
59
59
  `import type { StandardSchemaV1 } from 'nitro-graphql'`,
60
60
  `
61
61
  export type SchemaType = Partial<Record<Partial<keyof ResolversTypes>, StandardSchemaV1>>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,