nitro-graphql 0.0.11 → 0.0.13
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/dist/ecosystem/nuxt.d.ts +2 -2
- package/dist/index.js +15 -12
- package/dist/routes/apollo-server.d.ts +2 -2
- package/dist/routes/graphql-yoga.d.ts +2 -2
- package/dist/routes/health.d.ts +2 -2
- package/dist/utils/apollo.d.ts +17 -0
- package/dist/utils/client-codegen.d.ts +23 -0
- package/dist/utils/client-codegen.js +17 -2
- package/dist/utils/define.d.ts +20 -0
- package/dist/utils/define.js +25 -0
- package/dist/utils/server-codegen.d.ts +7 -0
- package/dist/utils/server-type-generation.d.ts +7 -0
- package/package.json +1 -1
package/dist/ecosystem/nuxt.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _nuxt_schema1 from "@nuxt/schema";
|
|
2
2
|
|
|
3
3
|
//#region src/ecosystem/nuxt.d.ts
|
|
4
4
|
interface ModuleOptions {}
|
|
5
|
-
declare const _default:
|
|
5
|
+
declare const _default: _nuxt_schema1.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { ModuleOptions, _default as default };
|
package/dist/index.js
CHANGED
|
@@ -103,18 +103,21 @@ var src_default = defineNitroModule({
|
|
|
103
103
|
handler: join(runtime, "health"),
|
|
104
104
|
method: "get"
|
|
105
105
|
});
|
|
106
|
-
if (nitro.options.imports)
|
|
107
|
-
|
|
108
|
-
imports
|
|
109
|
-
"
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
if (nitro.options.imports) {
|
|
107
|
+
nitro.options.imports.presets ??= [];
|
|
108
|
+
nitro.options.imports.presets.push({
|
|
109
|
+
from: "nitro-graphql/utils/define",
|
|
110
|
+
imports: [
|
|
111
|
+
"defineResolver",
|
|
112
|
+
"defineMutation",
|
|
113
|
+
"defineQuery",
|
|
114
|
+
"defineSubscription",
|
|
115
|
+
"defineType",
|
|
116
|
+
"defineGraphQLConfig",
|
|
117
|
+
"defineSchema"
|
|
118
|
+
]
|
|
119
|
+
});
|
|
120
|
+
}
|
|
118
121
|
nitro.hooks.hook("rollup:before", (nitro$1, rollupConfig$1) => {
|
|
119
122
|
const manualChunks = rollupConfig$1.output?.manualChunks;
|
|
120
123
|
const chunkFiles = rollupConfig$1.output?.chunkFileNames;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h32 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/apollo-server.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h32.EventHandler<h32.EventHandlerRequest, any>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h36 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/graphql-yoga.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h36.EventHandler<h36.EventHandlerRequest, Promise<Response>>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
package/dist/routes/health.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as h34 from "h3";
|
|
2
2
|
|
|
3
3
|
//#region src/routes/health.d.ts
|
|
4
|
-
declare const _default:
|
|
4
|
+
declare const _default: h34.EventHandler<h34.EventHandlerRequest, Promise<{
|
|
5
5
|
status: string;
|
|
6
6
|
message: string;
|
|
7
7
|
timestamp: string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ApolloServer, BaseContext, ContextFunction } from "@apollo/server";
|
|
2
|
+
import { EventHandler, H3Event } from "h3";
|
|
3
|
+
import { WithRequired } from "@apollo/utils.withrequired";
|
|
4
|
+
import { Hooks } from "crossws";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/apollo.d.ts
|
|
7
|
+
interface H3ContextFunctionArgument {
|
|
8
|
+
event: H3Event;
|
|
9
|
+
}
|
|
10
|
+
interface H3HandlerOptions<TContext extends BaseContext> {
|
|
11
|
+
context?: ContextFunction<[H3ContextFunctionArgument], TContext>;
|
|
12
|
+
websocket?: Partial<Hooks>;
|
|
13
|
+
}
|
|
14
|
+
declare function startServerAndCreateH3Handler(server: ApolloServer<BaseContext> | (() => ApolloServer<BaseContext>), options?: H3HandlerOptions<BaseContext>): EventHandler;
|
|
15
|
+
declare function startServerAndCreateH3Handler<TContext extends BaseContext>(server: ApolloServer<TContext> | (() => ApolloServer<TContext>), options: WithRequired<H3HandlerOptions<TContext>, 'context'>): EventHandler;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { H3ContextFunctionArgument, H3HandlerOptions, startServerAndCreateH3Handler };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CodegenClientConfig } from "../types/index.js";
|
|
2
|
+
import { GraphQLSchema } from "graphql";
|
|
3
|
+
import { Source } from "@graphql-tools/utils";
|
|
4
|
+
import { LoadSchemaOptions, UnnormalizedTypeDefPointer } from "@graphql-tools/load";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/client-codegen.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Type definition pointer for GraphQL schemas
|
|
10
|
+
*/
|
|
11
|
+
type GraphQLTypeDefPointer = UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[];
|
|
12
|
+
/**
|
|
13
|
+
* Options for loading GraphQL schemas
|
|
14
|
+
*/
|
|
15
|
+
type GraphQLLoadSchemaOptions = Partial<LoadSchemaOptions>;
|
|
16
|
+
declare function graphQLLoadSchemaSync(schemaPointers: GraphQLTypeDefPointer, data?: GraphQLLoadSchemaOptions): Promise<GraphQLSchema | undefined>;
|
|
17
|
+
declare function loadGraphQLDocuments(patterns: string | string[]): Promise<Source[]>;
|
|
18
|
+
declare function generateClientTypes(schema: GraphQLSchema, docs: Source[], config?: CodegenClientConfig, outputPath?: string): Promise<false | {
|
|
19
|
+
types: string;
|
|
20
|
+
sdk: string;
|
|
21
|
+
}>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, generateClientTypes, graphQLLoadSchemaSync, loadGraphQLDocuments };
|
|
@@ -8,7 +8,7 @@ import { plugin } from "@graphql-codegen/typescript";
|
|
|
8
8
|
import { plugin as plugin$1 } from "@graphql-codegen/typescript-generic-sdk";
|
|
9
9
|
import { plugin as plugin$2 } from "@graphql-codegen/typescript-operations";
|
|
10
10
|
import { GraphQLFileLoader } from "@graphql-tools/graphql-file-loader";
|
|
11
|
-
import { loadDocuments } from "@graphql-tools/load";
|
|
11
|
+
import { loadDocuments, loadSchemaSync } from "@graphql-tools/load";
|
|
12
12
|
|
|
13
13
|
//#region src/utils/client-codegen.ts
|
|
14
14
|
function pluginContent(_schema, _documents, _config, _info) {
|
|
@@ -23,6 +23,21 @@ function pluginContent(_schema, _documents, _config, _info) {
|
|
|
23
23
|
content: ""
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
async function graphQLLoadSchemaSync(schemaPointers, data = {}) {
|
|
27
|
+
const pointers = Array.isArray(schemaPointers) ? schemaPointers : [schemaPointers];
|
|
28
|
+
const filteredPointers = [...pointers, "!**/vfs/**"];
|
|
29
|
+
let result;
|
|
30
|
+
try {
|
|
31
|
+
result = loadSchemaSync(filteredPointers, {
|
|
32
|
+
...data,
|
|
33
|
+
loaders: [new GraphQLFileLoader(), ...data.loaders || []]
|
|
34
|
+
});
|
|
35
|
+
} catch (e) {
|
|
36
|
+
if ((e.message || "").includes("Unable to find any GraphQL type definitions for the following pointers:")) consola$1.info("No server GraphQL files found. If you need server-side GraphQL, add .graphql files to your server directory.");
|
|
37
|
+
else throw e;
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
26
41
|
async function loadGraphQLDocuments(patterns) {
|
|
27
42
|
try {
|
|
28
43
|
const result = await loadDocuments(patterns, { loaders: [new GraphQLFileLoader()] });
|
|
@@ -118,4 +133,4 @@ async function generateClientTypes(schema, docs, config = {}, outputPath) {
|
|
|
118
133
|
}
|
|
119
134
|
|
|
120
135
|
//#endregion
|
|
121
|
-
export { generateClientTypes, loadGraphQLDocuments };
|
|
136
|
+
export { generateClientTypes, graphQLLoadSchemaSync, loadGraphQLDocuments };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApolloServerOptions, BaseContext } from "@apollo/server";
|
|
2
|
+
import { YogaServerOptions } from "graphql-yoga";
|
|
3
|
+
import { ResolversTypes, StandardSchemaV1 } from "#graphql/server";
|
|
4
|
+
import { GraphQLFramework, Resolvers } from "nitro-graphql";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/define.d.ts
|
|
7
|
+
type Flatten<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
|
|
8
|
+
declare function defineSchema<T extends Partial<Record<keyof ResolversTypes, StandardSchemaV1>>>(config: T): Flatten<T>;
|
|
9
|
+
declare function defineResolver(resolvers: Resolvers): Resolvers;
|
|
10
|
+
type ResolverQuery = Resolvers extends {
|
|
11
|
+
Query: infer Q;
|
|
12
|
+
} ? Q : never;
|
|
13
|
+
declare function defineQuery(resolvers?: Resolvers['Query']): Resolvers;
|
|
14
|
+
declare function defineMutation(resolvers?: Resolvers['Mutation']): Resolvers;
|
|
15
|
+
declare function defineSubscription(resolvers?: Resolvers['Subscription']): Resolvers;
|
|
16
|
+
declare function defineType(resolvers: Resolvers): Resolvers;
|
|
17
|
+
type DefineServerConfig = GraphQLFramework extends 'graphql-yoga' ? Partial<YogaServerOptions<any, any>> : GraphQLFramework extends 'apollo-server' ? Partial<ApolloServerOptions<BaseContext>> : Record<string, any>;
|
|
18
|
+
declare function defineGraphQLConfig(config: Partial<DefineServerConfig>): Partial<DefineServerConfig>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { DefineServerConfig, ResolverQuery, defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/utils/define.ts
|
|
2
|
+
function defineSchema(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
5
|
+
function defineResolver(resolvers) {
|
|
6
|
+
return resolvers;
|
|
7
|
+
}
|
|
8
|
+
function defineQuery(resolvers = {}) {
|
|
9
|
+
return { Query: { ...resolvers } };
|
|
10
|
+
}
|
|
11
|
+
function defineMutation(resolvers = {}) {
|
|
12
|
+
return { Mutation: { ...resolvers } };
|
|
13
|
+
}
|
|
14
|
+
function defineSubscription(resolvers = {}) {
|
|
15
|
+
return { Subscription: { ...resolvers } };
|
|
16
|
+
}
|
|
17
|
+
function defineType(resolvers) {
|
|
18
|
+
return resolvers;
|
|
19
|
+
}
|
|
20
|
+
function defineGraphQLConfig(config) {
|
|
21
|
+
return config;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { defineGraphQLConfig, defineMutation, defineQuery, defineResolver, defineSchema, defineSubscription, defineType };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CodegenServerConfig } from "../types/index.js";
|
|
2
|
+
import { GraphQLSchema } from "graphql";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/server-codegen.d.ts
|
|
5
|
+
declare function generateTypes(schema: GraphQLSchema, config?: CodegenServerConfig, outputPath?: string): Promise<string>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { generateTypes };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Nitro } from "nitropack";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/server-type-generation.d.ts
|
|
4
|
+
declare function serverTypeGeneration(app: Nitro): Promise<void>;
|
|
5
|
+
declare function clientTypeGeneration(app: Nitro, path: string): Promise<void>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { clientTypeGeneration, serverTypeGeneration };
|