nitro-graphql 1.4.2 → 1.4.3

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.
@@ -1,4 +1,3 @@
1
- import { startServerAndCreateH3Handler } from "../utils/apollo.js";
2
1
  import { consola as consola$1 } from "consola";
3
2
  import defu from "defu";
4
3
  import { parse } from "graphql";
@@ -12,6 +11,7 @@ import { ApolloServer } from "@apollo/server";
12
11
  import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
13
12
  import { makeExecutableSchema } from "@graphql-tools/schema";
14
13
  import { defineEventHandler } from "h3";
14
+ import { startServerAndCreateH3Handler } from "nitro-graphql/utils/apollo";
15
15
 
16
16
  //#region src/routes/apollo-server.ts
17
17
  let buildSubgraphSchema = null;
@@ -65,6 +65,7 @@ async function createMergedSchema() {
65
65
  }
66
66
  }
67
67
  let apolloServer = null;
68
+ let serverStarted = false;
68
69
  async function createApolloServer() {
69
70
  if (!apolloServer) {
70
71
  const schema = await createMergedSchema();
@@ -73,6 +74,10 @@ async function createApolloServer() {
73
74
  introspection: true,
74
75
  plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })]
75
76
  }, importedConfig));
77
+ if (!serverStarted) {
78
+ await apolloServer.start();
79
+ serverStarted = true;
80
+ }
76
81
  }
77
82
  return apolloServer;
78
83
  }
@@ -80,7 +85,10 @@ let serverPromise = null;
80
85
  var apollo_server_default = defineEventHandler(async (event) => {
81
86
  if (!serverPromise) serverPromise = createApolloServer();
82
87
  const server = await serverPromise;
83
- const h3Handler = startServerAndCreateH3Handler(server, { context: async () => ({ event }) });
88
+ const h3Handler = startServerAndCreateH3Handler(server, {
89
+ context: async () => ({ event }),
90
+ serverAlreadyStarted: true
91
+ });
84
92
  return h3Handler(event);
85
93
  });
86
94
 
@@ -1,6 +1,6 @@
1
- import * as h33 from "h3";
1
+ import * as h31 from "h3";
2
2
 
3
3
  //#region src/routes/graphql-yoga.d.ts
4
- declare const _default: h33.EventHandler<h33.EventHandlerRequest, Promise<Response>>;
4
+ declare const _default: h31.EventHandler<h31.EventHandlerRequest, Promise<Response>>;
5
5
  //#endregion
6
6
  export { _default as default };
@@ -1,7 +1,7 @@
1
- import * as h31 from "h3";
1
+ import * as h33 from "h3";
2
2
 
3
3
  //#region src/routes/health.d.ts
4
- declare const _default: h31.EventHandler<h31.EventHandlerRequest, Promise<{
4
+ declare const _default: h33.EventHandler<h33.EventHandlerRequest, Promise<{
5
5
  status: string;
6
6
  message: string;
7
7
  timestamp: string;
@@ -10,6 +10,7 @@ interface H3ContextFunctionArgument {
10
10
  interface H3HandlerOptions<TContext extends BaseContext> {
11
11
  context?: ContextFunction<[H3ContextFunctionArgument], TContext>;
12
12
  websocket?: Partial<Hooks>;
13
+ serverAlreadyStarted?: boolean;
13
14
  }
14
15
  declare function startServerAndCreateH3Handler(server: ApolloServer<BaseContext> | (() => ApolloServer<BaseContext>), options?: H3HandlerOptions<BaseContext>): EventHandler;
15
16
  declare function startServerAndCreateH3Handler<TContext extends BaseContext>(server: ApolloServer<TContext> | (() => ApolloServer<TContext>), options: WithRequired<H3HandlerOptions<TContext>, 'context'>): EventHandler;
@@ -8,7 +8,7 @@ function startServerAndCreateH3Handler(server, options) {
8
8
  return eventHandler({
9
9
  handler: async (event) => {
10
10
  const apolloServer = typeof server === "function" ? server() : server;
11
- apolloServer.startInBackgroundHandlingStartupErrorsByLoggingAndFailingAllRequests();
11
+ if (!options?.serverAlreadyStarted) apolloServer.startInBackgroundHandlingStartupErrorsByLoggingAndFailingAllRequests();
12
12
  if (isMethod(event, "OPTIONS")) return null;
13
13
  try {
14
14
  const graphqlRequest = await toGraphqlRequest(event);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nitro-graphql",
3
3
  "type": "module",
4
- "version": "1.4.2",
4
+ "version": "1.4.3",
5
5
  "description": "GraphQL integration for Nitro",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,
@@ -40,6 +40,10 @@
40
40
  "types": "./dist/utils/define.d.ts",
41
41
  "import": "./dist/utils/define.js"
42
42
  },
43
+ "./utils/apollo": {
44
+ "types": "./dist/utils/apollo.d.ts",
45
+ "import": "./dist/utils/apollo.js"
46
+ },
43
47
  "./internal": {
44
48
  "types": "./dist/internal/index.d.ts",
45
49
  "import": "./dist/internal/index.js"
@@ -112,7 +116,7 @@
112
116
  "changelogen": "^0.6.2",
113
117
  "crossws": "0.3.5",
114
118
  "eslint": "^9.34.0",
115
- "graphql": "^16.11.0",
119
+ "graphql": "16.11.0",
116
120
  "graphql-yoga": "^5.15.1",
117
121
  "h3": "1.15.3",
118
122
  "nitropack": "^2.12.5",