nitro-graphql 2.0.0-beta.72 → 2.0.0-beta.73
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 +1 -1
- package/dist/cli/adapter.d.mts +0 -3
- package/dist/cli/adapter.mjs +6 -29
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/config.d.mts +4 -5
- package/dist/cli/config.mjs +3 -1
- package/dist/cli/index.d.mts +3 -6
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/server/graphql-handler.mjs +2 -1
- package/dist/cli/server/watcher.mjs +1 -1
- package/dist/core/codegen/client.d.mts +4 -27
- package/dist/core/codegen/client.mjs +26 -445
- package/dist/core/codegen/file-header.d.mts +7 -0
- package/dist/core/codegen/file-header.mjs +12 -0
- package/dist/core/codegen/index.d.mts +7 -5
- package/dist/core/codegen/index.mjs +7 -5
- package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -1
- package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +1 -1
- package/dist/core/codegen/schema-loader.d.mts +2 -7
- package/dist/core/codegen/schema-loader.mjs +65 -70
- package/dist/core/codegen/server-type-helpers.d.mts +14 -0
- package/dist/core/codegen/server-type-helpers.mjs +76 -0
- package/dist/core/codegen/server.d.mts +1 -15
- package/dist/core/codegen/server.mjs +15 -105
- package/dist/core/codegen/subscription-extractor.d.mts +20 -0
- package/dist/core/codegen/subscription-extractor.mjs +30 -0
- package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
- package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
- package/dist/core/constants.d.mts +5 -53
- package/dist/core/constants.mjs +13 -54
- package/dist/core/create-config.d.mts +31 -0
- package/dist/core/create-config.mjs +42 -0
- package/dist/core/debug/index.d.mts +2 -2
- package/dist/core/debug/index.mjs +2 -2
- package/dist/core/debug/template.d.mts +1 -5
- package/dist/core/debug/template.mjs +1 -1
- package/dist/core/extend/loader.d.mts +0 -1
- package/dist/core/extend/loader.mjs +59 -89
- package/dist/core/index.d.mts +22 -17
- package/dist/core/index.mjs +19 -15
- package/dist/core/manifest.mjs +3 -1
- package/dist/core/pubsub/index.d.mts +2 -109
- package/dist/core/pubsub/index.mjs +1 -145
- package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
- package/dist/core/pubsub/memory-pubsub.mjs +146 -0
- package/dist/core/scanning/ast-scanner.mjs +4 -2
- package/dist/core/scanning/directives.mjs +2 -3
- package/dist/core/scanning/documents.d.mts +4 -3
- package/dist/core/scanning/documents.mjs +1 -1
- package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
- package/dist/core/scanning/{common.mjs → file-scanner.mjs} +2 -10
- package/dist/core/scanning/index.d.mts +3 -3
- package/dist/core/scanning/index.mjs +3 -3
- package/dist/core/scanning/resolvers.mjs +8 -9
- package/dist/core/scanning/schemas.d.mts +1 -5
- package/dist/core/scanning/schemas.mjs +2 -24
- package/dist/core/schema/builder.d.mts +4 -2
- package/dist/core/schema/builder.mjs +4 -2
- package/dist/core/schema/index.d.mts +2 -2
- package/dist/core/schema/index.mjs +2 -2
- package/dist/core/server/apollo.d.mts +20 -0
- package/dist/core/server/apollo.mjs +54 -0
- package/dist/core/server/index.d.mts +4 -2
- package/dist/core/server/index.mjs +3 -2
- package/dist/core/server/types.d.mts +7 -14
- package/dist/core/server/types.mjs +15 -1
- package/dist/core/server/yoga.d.mts +1 -7
- package/dist/core/server/yoga.mjs +4 -13
- package/dist/core/types/adapter.d.mts +4 -39
- package/dist/core/types/codegen.d.mts +22 -45
- package/dist/core/types/config.d.mts +33 -121
- package/dist/core/types/define.d.mts +8 -5
- package/dist/core/types/index.d.mts +5 -4
- package/dist/core/types/scanning.d.mts +4 -1
- package/dist/core/types/standard-schema.d.mts +64 -0
- package/dist/core/utils/directive-parser.d.mts +8 -63
- package/dist/core/utils/directive-parser.mjs +114 -166
- package/dist/core/utils/file-io.d.mts +1 -5
- package/dist/core/utils/file-io.mjs +1 -11
- package/dist/core/utils/index.d.mts +5 -4
- package/dist/core/utils/index.mjs +6 -5
- package/dist/core/utils/logger.d.mts +1 -10
- package/dist/core/utils/logger.mjs +1 -19
- package/dist/core/utils/ofetch-templates.mjs +3 -4
- package/dist/core/utils/runtime.d.mts +1 -30
- package/dist/core/utils/runtime.mjs +2 -44
- package/dist/core/utils/string.d.mts +10 -0
- package/dist/core/utils/string.mjs +12 -0
- package/dist/core/watcher/create-watcher.d.mts +103 -0
- package/dist/core/watcher/create-watcher.mjs +143 -0
- package/dist/core/watcher/index.d.mts +2 -107
- package/dist/core/watcher/index.mjs +1 -139
- package/dist/define.d.mts +4 -2
- package/dist/define.mjs +7 -6
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +1 -1
- package/dist/nitro/adapter.d.mts +6 -10
- package/dist/nitro/adapter.mjs +12 -42
- package/dist/nitro/codegen/client-types.d.mts +12 -0
- package/dist/nitro/codegen/client-types.mjs +73 -0
- package/dist/nitro/codegen/external-types.d.mts +8 -0
- package/dist/nitro/codegen/external-types.mjs +47 -0
- package/dist/nitro/codegen/index.d.mts +4 -0
- package/dist/nitro/codegen/index.mjs +4 -0
- package/dist/nitro/codegen/server-types.d.mts +12 -0
- package/dist/nitro/codegen/server-types.mjs +81 -0
- package/dist/nitro/defaults.d.mts +28 -0
- package/dist/nitro/defaults.mjs +34 -0
- package/dist/nitro/index.d.mts +11 -3
- package/dist/nitro/index.mjs +1 -1
- package/dist/nitro/paths.d.mts +3 -2
- package/dist/nitro/paths.mjs +13 -9
- package/dist/nitro/rollup.mjs +4 -3
- package/dist/nitro/routes/_ws-handler.d.mts +6 -0
- package/dist/nitro/routes/_ws-handler.mjs +49 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
- package/dist/nitro/routes/apollo-server-ws.mjs +9 -44
- package/dist/nitro/routes/apollo-server.d.mts +1 -1
- package/dist/nitro/routes/apollo-server.mjs +16 -55
- package/dist/nitro/routes/debug.d.mts +1 -1
- package/dist/nitro/routes/debug.mjs +1 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +1 -1
- package/dist/nitro/routes/graphql-yoga-ws.mjs +6 -44
- package/dist/nitro/routes/graphql-yoga.mjs +7 -5
- package/dist/nitro/routes/health.mjs +22 -24
- package/dist/nitro/setup/extend-loader.d.mts +6 -5
- package/dist/nitro/setup/extend-loader.mjs +30 -58
- package/dist/nitro/setup/file-watcher.mjs +6 -4
- package/dist/nitro/setup/logging.d.mts +1 -8
- package/dist/nitro/setup/logging.mjs +7 -22
- package/dist/nitro/setup/rollup-integration.mjs +32 -1
- package/dist/nitro/setup/scanner.d.mts +8 -43
- package/dist/nitro/setup/scanner.mjs +56 -58
- package/dist/nitro/setup/security.d.mts +10 -0
- package/dist/nitro/setup/security.mjs +17 -0
- package/dist/nitro/setup/type-generation.d.mts +13 -0
- package/dist/nitro/setup/type-generation.mjs +16 -0
- package/dist/nitro/setup.d.mts +4 -3
- package/dist/nitro/setup.mjs +87 -74
- package/dist/nitro/state.d.mts +32 -0
- package/dist/nitro/state.mjs +58 -0
- package/dist/nitro/types/augmentation.d.mts +59 -0
- package/dist/nitro/types/augmentation.mjs +1 -0
- package/dist/nitro/types/config.d.mts +327 -0
- package/dist/nitro/types/config.mjs +1 -0
- package/dist/nitro/types/define.d.mts +13 -0
- package/dist/nitro/types/define.mjs +1 -0
- package/dist/nitro/types/index.d.mts +10 -0
- package/dist/nitro/types/index.mjs +1 -0
- package/dist/nitro/virtual/debug-info.d.mts +9 -0
- package/dist/nitro/virtual/debug-info.mjs +35 -0
- package/dist/nitro/virtual/graphql-config.d.mts +9 -0
- package/dist/nitro/virtual/graphql-config.mjs +33 -0
- package/dist/nitro/virtual/index.d.mts +25 -0
- package/dist/nitro/virtual/index.mjs +45 -0
- package/dist/nitro/virtual/module-config.d.mts +9 -0
- package/dist/nitro/virtual/module-config.mjs +10 -0
- package/dist/nitro/virtual/pubsub.d.mts +9 -0
- package/dist/nitro/virtual/pubsub.mjs +17 -0
- package/dist/nitro/virtual/server-directives.d.mts +9 -0
- package/dist/nitro/virtual/server-directives.mjs +12 -0
- package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
- package/dist/nitro/virtual/server-resolvers.mjs +17 -0
- package/dist/nitro/virtual/server-schemas.d.mts +9 -0
- package/dist/nitro/virtual/server-schemas.mjs +31 -0
- package/dist/nitro/virtual/stubs.d.mts +42 -10
- package/dist/nitro/virtual/stubs.mjs +0 -5
- package/dist/nitro/virtual/utils.d.mts +15 -0
- package/dist/nitro/virtual/utils.mjs +26 -0
- package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
- package/dist/nitro/virtual/validation-schemas.mjs +33 -0
- package/native/index.js +52 -52
- package/package.json +15 -15
- package/dist/cli/commands/index.d.mts +0 -5
- package/dist/cli/commands/index.mjs +0 -5
- package/dist/core/codegen/plugin.d.mts +0 -19
- package/dist/core/codegen/plugin.mjs +0 -29
- package/dist/core/config.d.mts +0 -45
- package/dist/core/config.mjs +0 -76
- package/dist/nitro/codegen.d.mts +0 -18
- package/dist/nitro/codegen.mjs +0 -171
- package/dist/nitro/config.d.mts +0 -50
- package/dist/nitro/config.mjs +0 -55
- package/dist/nitro/types.d.mts +0 -549
- package/dist/nitro/virtual/generators.d.mts +0 -38
- package/dist/nitro/virtual/generators.mjs +0 -190
- /package/dist/{nitro/types.mjs → core/types/standard-schema.mjs} +0 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { extractSubscriptions } from "./subscription-extractor.mjs";
|
|
2
|
+
//#region src/core/codegen/vue-subscription-builder.ts
|
|
3
|
+
/**
|
|
4
|
+
* Generate subscription builder code (Drizzle-style API) + Vue Composables
|
|
5
|
+
* Returns empty string if subscriptions are not enabled or no subscription operations found
|
|
6
|
+
*/
|
|
7
|
+
function generateSubscriptionBuilder(docs, subscriptionsEnabled) {
|
|
8
|
+
if (!subscriptionsEnabled) return "";
|
|
9
|
+
const subscriptions = extractSubscriptions(docs);
|
|
10
|
+
if (subscriptions.length === 0) return "";
|
|
11
|
+
let output = `
|
|
12
|
+
// === Subscription Imports ===
|
|
13
|
+
import { ref, onUnmounted, computed } from 'vue'
|
|
14
|
+
import type { Ref } from 'vue'
|
|
15
|
+
import type {
|
|
16
|
+
ConnectionState,
|
|
17
|
+
SubscriptionHandle,
|
|
18
|
+
SubscriptionSession,
|
|
19
|
+
SubscriptionTransport,
|
|
20
|
+
TransportOptions,
|
|
21
|
+
} from 'nitro-graphql/subscribe'
|
|
22
|
+
import { subscriptionClient } from './subscribe'
|
|
23
|
+
|
|
24
|
+
// === Subscription Types ===
|
|
25
|
+
export type { ConnectionState, SubscriptionHandle, SubscriptionSession, SubscriptionTransport, TransportOptions }
|
|
26
|
+
|
|
27
|
+
export interface UseSubscriptionOptions<T> {
|
|
28
|
+
/** Auto-start subscription on mount (default: false) */
|
|
29
|
+
immediate?: boolean
|
|
30
|
+
/** Callback when subscription starts */
|
|
31
|
+
onStart?: () => void
|
|
32
|
+
/** Callback when subscription stops */
|
|
33
|
+
onStop?: () => void
|
|
34
|
+
/** Callback when data is received */
|
|
35
|
+
onData?: (data: T) => void
|
|
36
|
+
/** Callback when error occurs */
|
|
37
|
+
onError?: (error: Error) => void
|
|
38
|
+
/** Callback when WebSocket connects */
|
|
39
|
+
onConnected?: () => void
|
|
40
|
+
/** Callback when WebSocket reconnects */
|
|
41
|
+
onReconnected?: () => void
|
|
42
|
+
/** Callback when WebSocket disconnects */
|
|
43
|
+
onDisconnected?: () => void
|
|
44
|
+
/** Callback when connection state changes */
|
|
45
|
+
onStateChange?: (state: ConnectionState) => void
|
|
46
|
+
/** Use existing session for multiplexing (pass result from useSubscriptionSession) */
|
|
47
|
+
session?: UseSubscriptionSessionReturn
|
|
48
|
+
/** Transport type: 'websocket' (default), 'sse', or 'auto' (WS first, SSE fallback) */
|
|
49
|
+
transport?: SubscriptionTransport
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface UseSubscriptionReturn<T> {
|
|
53
|
+
/** Reactive subscription data */
|
|
54
|
+
data: Ref<T | null>
|
|
55
|
+
/** Reactive error state */
|
|
56
|
+
error: Ref<Error | null>
|
|
57
|
+
/** Is subscription active */
|
|
58
|
+
isActive: Ref<boolean>
|
|
59
|
+
/** Connection state */
|
|
60
|
+
state: Ref<ConnectionState>
|
|
61
|
+
/** Active transport type ('websocket' | 'sse') */
|
|
62
|
+
transport: Ref<'websocket' | 'sse'>
|
|
63
|
+
/** Start subscription */
|
|
64
|
+
start: () => void
|
|
65
|
+
/** Stop subscription */
|
|
66
|
+
stop: () => void
|
|
67
|
+
/** Restart subscription */
|
|
68
|
+
restart: () => void
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// === Subscription Builder (Drizzle-style API) ===
|
|
72
|
+
interface SubscriptionBuilder<TData> {
|
|
73
|
+
onData(fn: (data: TData) => void): SubscriptionBuilder<TData>
|
|
74
|
+
onError(fn: (error: Error) => void): SubscriptionBuilder<TData>
|
|
75
|
+
start(): SubscriptionHandle
|
|
76
|
+
subscribe(fn: (data: TData) => void): SubscriptionHandle
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function createSubscriptionBuilder<TData>(query: string, variables: unknown): SubscriptionBuilder<TData> {
|
|
80
|
+
let onDataFn: ((data: TData) => void) | undefined
|
|
81
|
+
let onErrorFn: ((error: Error) => void) | undefined
|
|
82
|
+
|
|
83
|
+
const builder: SubscriptionBuilder<TData> = {
|
|
84
|
+
onData(fn: (data: TData) => void) {
|
|
85
|
+
onDataFn = fn
|
|
86
|
+
return builder
|
|
87
|
+
},
|
|
88
|
+
onError(fn: (error: Error) => void) {
|
|
89
|
+
onErrorFn = fn
|
|
90
|
+
return builder
|
|
91
|
+
},
|
|
92
|
+
start(): SubscriptionHandle {
|
|
93
|
+
return subscriptionClient.subscribe(query, variables, onDataFn, onErrorFn)
|
|
94
|
+
},
|
|
95
|
+
subscribe(fn: (data: TData) => void): SubscriptionHandle {
|
|
96
|
+
return subscriptionClient.subscribe(query, variables, fn, undefined)
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return builder
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const subscription = {
|
|
104
|
+
`;
|
|
105
|
+
for (const sub of subscriptions) if (sub.hasVariables) output += ` ${sub.typeName}(variables: Types.${sub.typeName}SubscriptionVariables): SubscriptionBuilder<Types.${sub.typeName}Subscription['${sub.fieldName}']> {
|
|
106
|
+
return createSubscriptionBuilder<Types.${sub.typeName}Subscription['${sub.fieldName}']>(${sub.typeName}Document, variables)
|
|
107
|
+
},
|
|
108
|
+
`;
|
|
109
|
+
else output += ` ${sub.typeName}(): SubscriptionBuilder<Types.${sub.typeName}Subscription['${sub.fieldName}']> {
|
|
110
|
+
return createSubscriptionBuilder<Types.${sub.typeName}Subscription['${sub.fieldName}']>(${sub.typeName}Document, undefined)
|
|
111
|
+
},
|
|
112
|
+
`;
|
|
113
|
+
output += `}
|
|
114
|
+
|
|
115
|
+
// === Framework-Agnostic Session (for non-Vue usage) ===
|
|
116
|
+
/**
|
|
117
|
+
* Create a multiplexed subscription session (framework-agnostic)
|
|
118
|
+
* All subscriptions share a single WebSocket connection.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Vanilla JS / Node.js / React / etc.
|
|
122
|
+
* const session = createSubscriptionSession()
|
|
123
|
+
* const sub1 = session.subscribe(query1, vars1, onData1)
|
|
124
|
+
* const sub2 = session.subscribe(query2, vars2, onData2)
|
|
125
|
+
* // Both use the same WebSocket connection
|
|
126
|
+
* sub1.unsubscribe()
|
|
127
|
+
* session.close() // Close all
|
|
128
|
+
*
|
|
129
|
+
* @returns SubscriptionSession - Framework-agnostic session object
|
|
130
|
+
*/
|
|
131
|
+
export function createSubscriptionSession(): SubscriptionSession {
|
|
132
|
+
return subscriptionClient.createSession()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// === Vue Composable: useSubscriptionSession (Multiplexing) ===
|
|
136
|
+
export interface UseSubscriptionSessionReturn {
|
|
137
|
+
/** The underlying session object */
|
|
138
|
+
session: SubscriptionSession
|
|
139
|
+
/** Subscribe using the shared session */
|
|
140
|
+
subscribe: <TData = unknown>(
|
|
141
|
+
query: string,
|
|
142
|
+
variables: unknown,
|
|
143
|
+
onData?: (data: TData) => void,
|
|
144
|
+
onError?: (error: Error) => void,
|
|
145
|
+
) => SubscriptionHandle
|
|
146
|
+
/** Close all subscriptions and the connection */
|
|
147
|
+
close: () => void
|
|
148
|
+
/** Is the session connected (reactive) */
|
|
149
|
+
isConnected: Ref<boolean>
|
|
150
|
+
/** Current connection state (reactive) */
|
|
151
|
+
state: Ref<ConnectionState>
|
|
152
|
+
/** Number of active subscriptions (reactive) */
|
|
153
|
+
subscriptionCount: Ref<number>
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Vue composable for multiplexed subscription session
|
|
158
|
+
* Provides reactive state and automatic cleanup on unmount.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* // Vue 3 component
|
|
162
|
+
* const session = useSubscriptionSession()
|
|
163
|
+
* const { data } = useCountdown({ from: 10 }, { session })
|
|
164
|
+
* // Session auto-closes on component unmount
|
|
165
|
+
*
|
|
166
|
+
* @returns UseSubscriptionSessionReturn - Vue-reactive session wrapper
|
|
167
|
+
*/
|
|
168
|
+
export function useSubscriptionSession(): UseSubscriptionSessionReturn {
|
|
169
|
+
const session = subscriptionClient.createSession()
|
|
170
|
+
|
|
171
|
+
// Use refs for reactivity (session getters are not reactive)
|
|
172
|
+
const isConnected = ref(session.isConnected)
|
|
173
|
+
const state = ref<ConnectionState>(session.state)
|
|
174
|
+
const subscriptionCount = ref(session.subscriptionCount)
|
|
175
|
+
|
|
176
|
+
// Update refs when session state changes
|
|
177
|
+
function updateRefs() {
|
|
178
|
+
isConnected.value = session.isConnected
|
|
179
|
+
state.value = session.state
|
|
180
|
+
subscriptionCount.value = session.subscriptionCount
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Subscribe to session state changes for automatic reactivity
|
|
184
|
+
const unsubscribeStateChange = session.onStateChange(() => {
|
|
185
|
+
updateRefs()
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
function subscribe<TData = unknown>(
|
|
189
|
+
query: string,
|
|
190
|
+
variables: unknown,
|
|
191
|
+
onData?: (data: TData) => void,
|
|
192
|
+
onError?: (error: Error) => void,
|
|
193
|
+
): SubscriptionHandle {
|
|
194
|
+
return session.subscribe(query, variables, onData as (data: unknown) => void, onError)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function close() {
|
|
198
|
+
session.close()
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
onUnmounted(() => {
|
|
202
|
+
unsubscribeStateChange()
|
|
203
|
+
close()
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
session,
|
|
208
|
+
subscribe,
|
|
209
|
+
close,
|
|
210
|
+
isConnected,
|
|
211
|
+
state,
|
|
212
|
+
subscriptionCount,
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// === Vue Composables ===
|
|
217
|
+
function createUseSubscription<TData, TVariables = undefined>(
|
|
218
|
+
query: string,
|
|
219
|
+
getVariables: () => TVariables,
|
|
220
|
+
): (options?: UseSubscriptionOptions<TData>) => UseSubscriptionReturn<TData> {
|
|
221
|
+
return (options: UseSubscriptionOptions<TData> = {}): UseSubscriptionReturn<TData> => {
|
|
222
|
+
const data = ref<TData | null>(null) as Ref<TData | null>
|
|
223
|
+
const error = ref<Error | null>(null)
|
|
224
|
+
const isActive = ref(false)
|
|
225
|
+
const state = ref<ConnectionState>('idle')
|
|
226
|
+
const transport = ref<'websocket' | 'sse'>('websocket')
|
|
227
|
+
let handle: SubscriptionHandle | null = null
|
|
228
|
+
|
|
229
|
+
// Resolve transport options
|
|
230
|
+
const transportOptions: TransportOptions = {
|
|
231
|
+
transport: options.transport,
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function start() {
|
|
235
|
+
stop()
|
|
236
|
+
isActive.value = true
|
|
237
|
+
error.value = null
|
|
238
|
+
options.onStart?.()
|
|
239
|
+
|
|
240
|
+
const variables = getVariables()
|
|
241
|
+
|
|
242
|
+
if (options.session) {
|
|
243
|
+
// Use existing session for multiplexing (WebSocket only)
|
|
244
|
+
handle = options.session.subscribe<TData>(
|
|
245
|
+
query,
|
|
246
|
+
variables,
|
|
247
|
+
(d: TData) => {
|
|
248
|
+
data.value = d
|
|
249
|
+
options.onData?.(d)
|
|
250
|
+
},
|
|
251
|
+
(e: Error) => {
|
|
252
|
+
error.value = e
|
|
253
|
+
options.onError?.(e)
|
|
254
|
+
},
|
|
255
|
+
)
|
|
256
|
+
transport.value = 'websocket'
|
|
257
|
+
} else {
|
|
258
|
+
// Create dedicated connection with transport selection
|
|
259
|
+
handle = subscriptionClient.subscribe<TData>(
|
|
260
|
+
query,
|
|
261
|
+
variables,
|
|
262
|
+
(d: TData) => {
|
|
263
|
+
data.value = d
|
|
264
|
+
options.onData?.(d)
|
|
265
|
+
},
|
|
266
|
+
(e: Error) => {
|
|
267
|
+
error.value = e
|
|
268
|
+
options.onError?.(e)
|
|
269
|
+
},
|
|
270
|
+
transportOptions,
|
|
271
|
+
)
|
|
272
|
+
// Update transport ref from handle
|
|
273
|
+
transport.value = handle.transport
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function stop() {
|
|
278
|
+
if (handle) {
|
|
279
|
+
handle.unsubscribe()
|
|
280
|
+
handle = null
|
|
281
|
+
isActive.value = false
|
|
282
|
+
options.onStop?.()
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function restart() {
|
|
287
|
+
stop()
|
|
288
|
+
start()
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (options.immediate) {
|
|
292
|
+
start()
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
onUnmounted(stop)
|
|
296
|
+
|
|
297
|
+
return { data, error, isActive, state, transport, start, stop, restart }
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// === Subscription Return Types ===
|
|
302
|
+
`;
|
|
303
|
+
for (const sub of subscriptions) {
|
|
304
|
+
const typeName = `Types.${sub.typeName}Subscription['${sub.fieldName}']`;
|
|
305
|
+
output += `/** Return type for use${sub.typeName} composable */
|
|
306
|
+
export type Use${sub.typeName}Return = UseSubscriptionReturn<${typeName}>
|
|
307
|
+
`;
|
|
308
|
+
}
|
|
309
|
+
output += `
|
|
310
|
+
// === Vue Composables ===
|
|
311
|
+
`;
|
|
312
|
+
for (const sub of subscriptions) {
|
|
313
|
+
const typeName = `Types.${sub.typeName}Subscription['${sub.fieldName}']`;
|
|
314
|
+
const varsType = `Types.${sub.typeName}SubscriptionVariables`;
|
|
315
|
+
if (sub.hasVariables) output += `/**
|
|
316
|
+
* Vue composable for ${sub.typeName} subscription
|
|
317
|
+
* @param variables - Subscription variables
|
|
318
|
+
* @param options - Subscription options (immediate, onData, onError, session, etc.)
|
|
319
|
+
* @returns Reactive subscription state: { data, error, isActive, state, start, stop, restart }
|
|
320
|
+
*/
|
|
321
|
+
export function use${sub.typeName}(
|
|
322
|
+
variables: ${varsType},
|
|
323
|
+
options?: UseSubscriptionOptions<${typeName}>,
|
|
324
|
+
): Use${sub.typeName}Return {
|
|
325
|
+
return createUseSubscription<${typeName}, ${varsType}>(
|
|
326
|
+
${sub.typeName}Document,
|
|
327
|
+
() => variables,
|
|
328
|
+
)(options)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
`;
|
|
332
|
+
else output += `/**
|
|
333
|
+
* Vue composable for ${sub.typeName} subscription
|
|
334
|
+
* @param options - Subscription options (immediate, onData, onError, session, etc.)
|
|
335
|
+
* @returns Reactive subscription state: { data, error, isActive, state, start, stop, restart }
|
|
336
|
+
*/
|
|
337
|
+
export function use${sub.typeName}(
|
|
338
|
+
options?: UseSubscriptionOptions<${typeName}>,
|
|
339
|
+
): Use${sub.typeName}Return {
|
|
340
|
+
return createUseSubscription<${typeName}, undefined>(
|
|
341
|
+
${sub.typeName}Document,
|
|
342
|
+
() => undefined,
|
|
343
|
+
)(options)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
`;
|
|
347
|
+
}
|
|
348
|
+
return output;
|
|
349
|
+
}
|
|
350
|
+
//#endregion
|
|
351
|
+
export { generateSubscriptionBuilder };
|
|
@@ -20,6 +20,10 @@ declare const DEFAULT_GRAPHQL_SCALARS: {
|
|
|
20
20
|
readonly output: "File";
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Default patterns to always ignore during scanning and file watching
|
|
25
|
+
*/
|
|
26
|
+
declare const DEFAULT_IGNORE_PATTERNS: readonly ["**/node_modules/**", "**/.git/**", "**/.output/**", "**/.nitro/**", "**/.nuxt/**", "**/.graphql/**", "**/dist/**"];
|
|
23
27
|
/**
|
|
24
28
|
* GraphQL schema file extensions
|
|
25
29
|
*/
|
|
@@ -53,31 +57,22 @@ declare const DIRECTIVE_GLOB_PATTERN: "**/*.directive.{ts,js}";
|
|
|
53
57
|
*/
|
|
54
58
|
declare const FRAMEWORK_NUXT: "nuxt";
|
|
55
59
|
declare const FRAMEWORK_NITRO: "nitro";
|
|
56
|
-
declare const FRAMEWORK_STANDALONE: "standalone";
|
|
57
60
|
/**
|
|
58
61
|
* GraphQL server framework identifiers
|
|
59
62
|
*/
|
|
60
63
|
declare const GRAPHQL_FRAMEWORK_YOGA: "graphql-yoga";
|
|
61
64
|
declare const GRAPHQL_FRAMEWORK_APOLLO: "apollo-server";
|
|
62
|
-
type Framework = typeof FRAMEWORK_NUXT | typeof FRAMEWORK_NITRO | typeof FRAMEWORK_STANDALONE;
|
|
63
65
|
type GraphQLFramework = typeof GRAPHQL_FRAMEWORK_YOGA | typeof GRAPHQL_FRAMEWORK_APOLLO;
|
|
64
66
|
/**
|
|
65
67
|
* Default directory names for GraphQL files
|
|
66
68
|
*/
|
|
67
69
|
declare const DIR_SERVER_GRAPHQL: "server/graphql";
|
|
68
|
-
declare const DIR_ROUTES_GRAPHQL: "routes/graphql";
|
|
69
70
|
declare const DIR_APP_GRAPHQL: "app/graphql";
|
|
70
71
|
declare const DIR_CLIENT_GRAPHQL: "graphql";
|
|
71
|
-
declare const DIR_EXTERNAL: "external";
|
|
72
72
|
/**
|
|
73
73
|
* Windows-compatible server GraphQL directory
|
|
74
74
|
*/
|
|
75
75
|
declare const DIR_SERVER_GRAPHQL_WIN: "server\\graphql";
|
|
76
|
-
/**
|
|
77
|
-
* Build directory names
|
|
78
|
-
*/
|
|
79
|
-
declare const DIR_BUILD_NITRO: ".nitro";
|
|
80
|
-
declare const DIR_BUILD_NUXT: ".nuxt";
|
|
81
76
|
/**
|
|
82
77
|
* Default GraphQL endpoint paths
|
|
83
78
|
*/
|
|
@@ -88,11 +83,9 @@ declare const ENDPOINT_DEBUG: "/_nitro/graphql/debug";
|
|
|
88
83
|
* Configuration and scaffold file names
|
|
89
84
|
*/
|
|
90
85
|
declare const FILE_GRAPHQL_CONFIG: "graphql.config.ts";
|
|
91
|
-
declare const FILE_SCHEMA_GRAPHQL: "schema.graphql";
|
|
92
86
|
declare const FILE_SCHEMA_TS: "schema.ts";
|
|
93
87
|
declare const FILE_CONFIG_TS: "config.ts";
|
|
94
88
|
declare const FILE_CONTEXT_DTS: "context.d.ts";
|
|
95
|
-
declare const FILE_CONTEXT_TS: "context.ts";
|
|
96
89
|
declare const FILE_INDEX_TS: "index.ts";
|
|
97
90
|
declare const FILE_OFETCH_TS: "ofetch.ts";
|
|
98
91
|
declare const FILE_SDK_TS: "sdk.ts";
|
|
@@ -102,7 +95,6 @@ declare const FILE_DIRECTIVES_GRAPHQL: "_directives.graphql";
|
|
|
102
95
|
*/
|
|
103
96
|
declare const FILE_SERVER_TYPES: "nitro-graphql-server.d.ts";
|
|
104
97
|
declare const FILE_CLIENT_TYPES: "nitro-graphql-client.d.ts";
|
|
105
|
-
declare const FILE_GRAPHQL_DTS: "graphql.d.ts";
|
|
106
98
|
/**
|
|
107
99
|
* Generated type file name patterns with placeholders
|
|
108
100
|
*/
|
|
@@ -127,21 +119,10 @@ declare const DEFINE_MUTATION: "defineMutation";
|
|
|
127
119
|
declare const DEFINE_FIELD: "defineField";
|
|
128
120
|
declare const DEFINE_SUBSCRIPTION: "defineSubscription";
|
|
129
121
|
declare const DEFINE_DIRECTIVE: "defineDirective";
|
|
130
|
-
declare const DEFINE_GRAPHQL_CONFIG: "defineGraphQLConfig";
|
|
131
|
-
declare const DEFINE_SCHEMA: "defineSchema";
|
|
132
|
-
type DefineFunction = typeof DEFINE_FUNCTIONS[number];
|
|
133
122
|
/**
|
|
134
123
|
* Built-in GraphQL scalar types (should not be flagged as duplicates)
|
|
135
124
|
*/
|
|
136
125
|
declare const BUILTIN_SCALARS: readonly ["String", "Int", "Float", "Boolean", "ID", "DateTime", "JSON"];
|
|
137
|
-
/**
|
|
138
|
-
* Codegen parser dependencies (always external)
|
|
139
|
-
*/
|
|
140
|
-
declare const CODEGEN_EXTERNALS: readonly ["oxc-parser", "@oxc-parser"];
|
|
141
|
-
/**
|
|
142
|
-
* Apollo Federation dependencies (external when federation disabled)
|
|
143
|
-
*/
|
|
144
|
-
declare const FEDERATION_EXTERNALS: readonly ["@apollo/subgraph", "@apollo/federation-internals", "@apollo/cache-control-types"];
|
|
145
126
|
/**
|
|
146
127
|
* Supported HTTP methods for GraphQL endpoints
|
|
147
128
|
*/
|
|
@@ -151,38 +132,9 @@ declare const GRAPHQL_HTTP_METHODS: readonly ["GET", "POST", "OPTIONS"];
|
|
|
151
132
|
*/
|
|
152
133
|
declare const DEFAULT_SERVER_TYPES_PATH: ".graphql/nitro-graphql-server.d.ts";
|
|
153
134
|
declare const DEFAULT_CLIENT_TYPES_PATH: ".graphql/nitro-graphql-client.d.ts";
|
|
154
|
-
/**
|
|
155
|
-
* Valid resolver export types detected from AST parsing
|
|
156
|
-
*/
|
|
157
|
-
declare const RESOLVER_TYPE_QUERY: "query";
|
|
158
|
-
declare const RESOLVER_TYPE_MUTATION: "mutation";
|
|
159
|
-
declare const RESOLVER_TYPE_RESOLVER: "resolver";
|
|
160
|
-
declare const RESOLVER_TYPE_TYPE: "type";
|
|
161
|
-
declare const RESOLVER_TYPE_SUBSCRIPTION: "subscription";
|
|
162
|
-
declare const RESOLVER_TYPE_DIRECTIVE: "directive";
|
|
163
|
-
type ResolverType = typeof RESOLVER_TYPE_QUERY | typeof RESOLVER_TYPE_MUTATION | typeof RESOLVER_TYPE_RESOLVER | typeof RESOLVER_TYPE_TYPE | typeof RESOLVER_TYPE_SUBSCRIPTION | typeof RESOLVER_TYPE_DIRECTIVE;
|
|
164
|
-
/**
|
|
165
|
-
* Placeholder strings used in path resolution
|
|
166
|
-
*/
|
|
167
|
-
declare const PLACEHOLDER_SERVICE_NAME: "{serviceName}";
|
|
168
|
-
declare const PLACEHOLDER_BUILD_DIR: "{buildDir}";
|
|
169
|
-
declare const PLACEHOLDER_ROOT_DIR: "{rootDir}";
|
|
170
|
-
declare const PLACEHOLDER_FRAMEWORK: "{framework}";
|
|
171
|
-
declare const PLACEHOLDER_TYPES_DIR: "{typesDir}";
|
|
172
|
-
declare const PLACEHOLDER_SERVER_DIR: "{serverDir}";
|
|
173
|
-
declare const PLACEHOLDER_CLIENT_DIR: "{clientDir}";
|
|
174
135
|
/**
|
|
175
136
|
* Logger tag for nitro-graphql module
|
|
176
137
|
*/
|
|
177
138
|
declare const LOG_TAG: "nitro-graphql";
|
|
178
|
-
/**
|
|
179
|
-
* HTTP status codes for error handling
|
|
180
|
-
*/
|
|
181
|
-
declare const HTTP_STATUS_BAD_REQUEST: 400;
|
|
182
|
-
declare const HTTP_STATUS_INTERNAL_ERROR: 500;
|
|
183
|
-
/**
|
|
184
|
-
* Default service directory name for main service
|
|
185
|
-
*/
|
|
186
|
-
declare const SERVICE_DEFAULT: "default";
|
|
187
139
|
//#endregion
|
|
188
|
-
export { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN,
|
|
140
|
+
export { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_IGNORE_PATTERNS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_CLIENT_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, GraphQLFramework, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN };
|
package/dist/core/constants.mjs
CHANGED
|
@@ -22,6 +22,18 @@ const DEFAULT_GRAPHQL_SCALARS = {
|
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
|
+
* Default patterns to always ignore during scanning and file watching
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_IGNORE_PATTERNS = [
|
|
28
|
+
"**/node_modules/**",
|
|
29
|
+
"**/.git/**",
|
|
30
|
+
"**/.output/**",
|
|
31
|
+
"**/.nitro/**",
|
|
32
|
+
"**/.nuxt/**",
|
|
33
|
+
"**/.graphql/**",
|
|
34
|
+
"**/dist/**"
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
25
37
|
* GraphQL schema file extensions
|
|
26
38
|
*/
|
|
27
39
|
const GRAPHQL_EXTENSIONS = [".graphql", ".gql"];
|
|
@@ -54,7 +66,6 @@ const DIRECTIVE_GLOB_PATTERN = "**/*.directive.{ts,js}";
|
|
|
54
66
|
*/
|
|
55
67
|
const FRAMEWORK_NUXT = "nuxt";
|
|
56
68
|
const FRAMEWORK_NITRO = "nitro";
|
|
57
|
-
const FRAMEWORK_STANDALONE = "standalone";
|
|
58
69
|
/**
|
|
59
70
|
* GraphQL server framework identifiers
|
|
60
71
|
*/
|
|
@@ -64,20 +75,13 @@ const GRAPHQL_FRAMEWORK_APOLLO = "apollo-server";
|
|
|
64
75
|
* Default directory names for GraphQL files
|
|
65
76
|
*/
|
|
66
77
|
const DIR_SERVER_GRAPHQL = "server/graphql";
|
|
67
|
-
const DIR_ROUTES_GRAPHQL = "routes/graphql";
|
|
68
78
|
const DIR_APP_GRAPHQL = "app/graphql";
|
|
69
79
|
const DIR_CLIENT_GRAPHQL = "graphql";
|
|
70
|
-
const DIR_EXTERNAL = "external";
|
|
71
80
|
/**
|
|
72
81
|
* Windows-compatible server GraphQL directory
|
|
73
82
|
*/
|
|
74
83
|
const DIR_SERVER_GRAPHQL_WIN = "server\\graphql";
|
|
75
84
|
/**
|
|
76
|
-
* Build directory names
|
|
77
|
-
*/
|
|
78
|
-
const DIR_BUILD_NITRO = ".nitro";
|
|
79
|
-
const DIR_BUILD_NUXT = ".nuxt";
|
|
80
|
-
/**
|
|
81
85
|
* Default GraphQL endpoint paths
|
|
82
86
|
*/
|
|
83
87
|
const ENDPOINT_GRAPHQL = "/api/graphql";
|
|
@@ -87,11 +91,9 @@ const ENDPOINT_DEBUG = "/_nitro/graphql/debug";
|
|
|
87
91
|
* Configuration and scaffold file names
|
|
88
92
|
*/
|
|
89
93
|
const FILE_GRAPHQL_CONFIG = "graphql.config.ts";
|
|
90
|
-
const FILE_SCHEMA_GRAPHQL = "schema.graphql";
|
|
91
94
|
const FILE_SCHEMA_TS = "schema.ts";
|
|
92
95
|
const FILE_CONFIG_TS = "config.ts";
|
|
93
96
|
const FILE_CONTEXT_DTS = "context.d.ts";
|
|
94
|
-
const FILE_CONTEXT_TS = "context.ts";
|
|
95
97
|
const FILE_INDEX_TS = "index.ts";
|
|
96
98
|
const FILE_OFETCH_TS = "ofetch.ts";
|
|
97
99
|
const FILE_SDK_TS = "sdk.ts";
|
|
@@ -101,7 +103,6 @@ const FILE_DIRECTIVES_GRAPHQL = "_directives.graphql";
|
|
|
101
103
|
*/
|
|
102
104
|
const FILE_SERVER_TYPES = "nitro-graphql-server.d.ts";
|
|
103
105
|
const FILE_CLIENT_TYPES = "nitro-graphql-client.d.ts";
|
|
104
|
-
const FILE_GRAPHQL_DTS = "graphql.d.ts";
|
|
105
106
|
/**
|
|
106
107
|
* Generated type file name patterns with placeholders
|
|
107
108
|
*/
|
|
@@ -133,8 +134,6 @@ const DEFINE_MUTATION = "defineMutation";
|
|
|
133
134
|
const DEFINE_FIELD = "defineField";
|
|
134
135
|
const DEFINE_SUBSCRIPTION = "defineSubscription";
|
|
135
136
|
const DEFINE_DIRECTIVE = "defineDirective";
|
|
136
|
-
const DEFINE_GRAPHQL_CONFIG = "defineGraphQLConfig";
|
|
137
|
-
const DEFINE_SCHEMA = "defineSchema";
|
|
138
137
|
/**
|
|
139
138
|
* Built-in GraphQL scalar types (should not be flagged as duplicates)
|
|
140
139
|
*/
|
|
@@ -148,18 +147,6 @@ const BUILTIN_SCALARS = [
|
|
|
148
147
|
"JSON"
|
|
149
148
|
];
|
|
150
149
|
/**
|
|
151
|
-
* Codegen parser dependencies (always external)
|
|
152
|
-
*/
|
|
153
|
-
const CODEGEN_EXTERNALS = ["oxc-parser", "@oxc-parser"];
|
|
154
|
-
/**
|
|
155
|
-
* Apollo Federation dependencies (external when federation disabled)
|
|
156
|
-
*/
|
|
157
|
-
const FEDERATION_EXTERNALS = [
|
|
158
|
-
"@apollo/subgraph",
|
|
159
|
-
"@apollo/federation-internals",
|
|
160
|
-
"@apollo/cache-control-types"
|
|
161
|
-
];
|
|
162
|
-
/**
|
|
163
150
|
* Supported HTTP methods for GraphQL endpoints
|
|
164
151
|
*/
|
|
165
152
|
const GRAPHQL_HTTP_METHODS = [
|
|
@@ -173,36 +160,8 @@ const GRAPHQL_HTTP_METHODS = [
|
|
|
173
160
|
const DEFAULT_SERVER_TYPES_PATH = ".graphql/nitro-graphql-server.d.ts";
|
|
174
161
|
const DEFAULT_CLIENT_TYPES_PATH = ".graphql/nitro-graphql-client.d.ts";
|
|
175
162
|
/**
|
|
176
|
-
* Valid resolver export types detected from AST parsing
|
|
177
|
-
*/
|
|
178
|
-
const RESOLVER_TYPE_QUERY = "query";
|
|
179
|
-
const RESOLVER_TYPE_MUTATION = "mutation";
|
|
180
|
-
const RESOLVER_TYPE_RESOLVER = "resolver";
|
|
181
|
-
const RESOLVER_TYPE_TYPE = "type";
|
|
182
|
-
const RESOLVER_TYPE_SUBSCRIPTION = "subscription";
|
|
183
|
-
const RESOLVER_TYPE_DIRECTIVE = "directive";
|
|
184
|
-
/**
|
|
185
|
-
* Placeholder strings used in path resolution
|
|
186
|
-
*/
|
|
187
|
-
const PLACEHOLDER_SERVICE_NAME = "{serviceName}";
|
|
188
|
-
const PLACEHOLDER_BUILD_DIR = "{buildDir}";
|
|
189
|
-
const PLACEHOLDER_ROOT_DIR = "{rootDir}";
|
|
190
|
-
const PLACEHOLDER_FRAMEWORK = "{framework}";
|
|
191
|
-
const PLACEHOLDER_TYPES_DIR = "{typesDir}";
|
|
192
|
-
const PLACEHOLDER_SERVER_DIR = "{serverDir}";
|
|
193
|
-
const PLACEHOLDER_CLIENT_DIR = "{clientDir}";
|
|
194
|
-
/**
|
|
195
163
|
* Logger tag for nitro-graphql module
|
|
196
164
|
*/
|
|
197
165
|
const LOG_TAG = "nitro-graphql";
|
|
198
|
-
/**
|
|
199
|
-
* HTTP status codes for error handling
|
|
200
|
-
*/
|
|
201
|
-
const HTTP_STATUS_BAD_REQUEST = 400;
|
|
202
|
-
const HTTP_STATUS_INTERNAL_ERROR = 500;
|
|
203
|
-
/**
|
|
204
|
-
* Default service directory name for main service
|
|
205
|
-
*/
|
|
206
|
-
const SERVICE_DEFAULT = "default";
|
|
207
166
|
//#endregion
|
|
208
|
-
export { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN,
|
|
167
|
+
export { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_IGNORE_PATTERNS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_CLIENT_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CoreConfig, CoreLogger } from "./types/config.mjs";
|
|
2
|
+
import { ScanContext } from "./types/scanning.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/core/create-config.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options for creating a CoreConfig
|
|
7
|
+
*/
|
|
8
|
+
interface CreateCoreConfigOptions {
|
|
9
|
+
rootDir: string;
|
|
10
|
+
buildDir?: string;
|
|
11
|
+
serverDir?: string;
|
|
12
|
+
clientDir?: string;
|
|
13
|
+
isNuxt?: boolean;
|
|
14
|
+
isDev?: boolean;
|
|
15
|
+
logger?: CoreLogger;
|
|
16
|
+
ignorePatterns?: string[];
|
|
17
|
+
security?: CoreConfig['security'];
|
|
18
|
+
federation?: CoreConfig['federation'];
|
|
19
|
+
codegen?: CoreConfig['codegen'];
|
|
20
|
+
externalServices?: CoreConfig['externalServices'];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a CoreConfig with sensible defaults
|
|
24
|
+
*/
|
|
25
|
+
declare function createCoreConfig(options: CreateCoreConfigOptions): CoreConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Create a ScanContext from CoreConfig
|
|
28
|
+
*/
|
|
29
|
+
declare function createScanContext(config: CoreConfig): ScanContext;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { CreateCoreConfigOptions, createCoreConfig, createScanContext };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { GRAPHQL_FRAMEWORK_YOGA } from "./constants.mjs";
|
|
2
|
+
import { createLogger } from "./utils/logger.mjs";
|
|
3
|
+
import { resolve } from "pathe";
|
|
4
|
+
//#region src/core/create-config.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a CoreConfig with sensible defaults
|
|
7
|
+
*/
|
|
8
|
+
function createCoreConfig(options) {
|
|
9
|
+
const { rootDir, isNuxt = false, isDev = process.env.NODE_ENV !== "production", logger = createLogger(), ignorePatterns = [], security, federation, codegen, externalServices } = options;
|
|
10
|
+
const buildDir = options.buildDir || resolve(rootDir, isNuxt ? ".nuxt" : ".nitro");
|
|
11
|
+
return {
|
|
12
|
+
rootDir,
|
|
13
|
+
buildDir,
|
|
14
|
+
serverDir: options.serverDir || resolve(rootDir, "server/graphql"),
|
|
15
|
+
clientDir: options.clientDir || resolve(rootDir, isNuxt ? "app/graphql" : "graphql"),
|
|
16
|
+
typesDir: resolve(buildDir, "types"),
|
|
17
|
+
framework: GRAPHQL_FRAMEWORK_YOGA,
|
|
18
|
+
isNuxt,
|
|
19
|
+
isDev,
|
|
20
|
+
logger,
|
|
21
|
+
ignorePatterns,
|
|
22
|
+
security,
|
|
23
|
+
federation,
|
|
24
|
+
codegen,
|
|
25
|
+
externalServices
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a ScanContext from CoreConfig
|
|
30
|
+
*/
|
|
31
|
+
function createScanContext(config) {
|
|
32
|
+
return {
|
|
33
|
+
rootDir: config.rootDir,
|
|
34
|
+
serverDir: config.serverDir,
|
|
35
|
+
clientDir: config.clientDir,
|
|
36
|
+
ignorePatterns: config.ignorePatterns,
|
|
37
|
+
isDev: config.isDev,
|
|
38
|
+
logger: config.logger
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { createCoreConfig, createScanContext };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DebugInfo,
|
|
2
|
-
export { DebugInfo,
|
|
1
|
+
import { DebugInfo, generateDebugHtml } from "./template.mjs";
|
|
2
|
+
export { DebugInfo, generateDebugHtml };
|