naystack 1.7.0 → 1.7.1

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.
Files changed (64) hide show
  1. package/README.md +39 -22
  2. package/dist/auth/email/client.d.mts +17 -0
  3. package/dist/auth/email/client.d.ts +17 -0
  4. package/dist/auth/email/index.cjs.js +3 -3
  5. package/dist/auth/email/index.d.mts +6 -6
  6. package/dist/auth/email/index.d.ts +6 -6
  7. package/dist/auth/email/index.esm.js +2 -2
  8. package/dist/auth/email/routes/delete.d.mts +3 -3
  9. package/dist/auth/email/routes/delete.d.ts +3 -3
  10. package/dist/auth/email/routes/get.d.mts +3 -3
  11. package/dist/auth/email/routes/get.d.ts +3 -3
  12. package/dist/auth/email/routes/post.d.mts +3 -3
  13. package/dist/auth/email/routes/post.d.ts +3 -3
  14. package/dist/auth/email/routes/put.d.mts +3 -3
  15. package/dist/auth/email/routes/put.d.ts +3 -3
  16. package/dist/auth/email/token.cjs.js +3 -3
  17. package/dist/auth/email/token.d.mts +2 -2
  18. package/dist/auth/email/token.d.ts +2 -2
  19. package/dist/auth/email/token.esm.js +3 -3
  20. package/dist/auth/email/types.d.mts +5 -4
  21. package/dist/auth/email/types.d.ts +5 -4
  22. package/dist/auth/email/utils.d.mts +3 -3
  23. package/dist/auth/email/utils.d.ts +3 -3
  24. package/dist/auth/google/get.d.mts +3 -3
  25. package/dist/auth/google/get.d.ts +3 -3
  26. package/dist/auth/google/index.cjs.js +3 -3
  27. package/dist/auth/google/index.d.mts +7 -7
  28. package/dist/auth/google/index.d.ts +7 -7
  29. package/dist/auth/google/index.esm.js +2 -2
  30. package/dist/auth/index.cjs.js +12 -12
  31. package/dist/auth/index.d.mts +3 -3
  32. package/dist/auth/index.d.ts +3 -3
  33. package/dist/auth/index.esm.js +9 -9
  34. package/dist/auth/instagram/index.cjs.js +6 -6
  35. package/dist/auth/instagram/index.d.mts +8 -9
  36. package/dist/auth/instagram/index.d.ts +8 -9
  37. package/dist/auth/instagram/index.esm.js +5 -5
  38. package/dist/auth/instagram/route.cjs.js +3 -3
  39. package/dist/auth/instagram/route.d.mts +3 -3
  40. package/dist/auth/instagram/route.d.ts +3 -3
  41. package/dist/auth/instagram/route.esm.js +3 -3
  42. package/dist/file/client.d.mts +7 -7
  43. package/dist/file/client.d.ts +7 -7
  44. package/dist/graphql/client.d.mts +5 -5
  45. package/dist/graphql/client.d.ts +5 -5
  46. package/dist/graphql/index.cjs.js +20 -6
  47. package/dist/graphql/index.d.mts +2 -2
  48. package/dist/graphql/index.d.ts +2 -2
  49. package/dist/graphql/index.esm.js +18 -4
  50. package/dist/graphql/init.cjs.js +3 -3
  51. package/dist/graphql/init.d.mts +4 -4
  52. package/dist/graphql/init.d.ts +4 -4
  53. package/dist/graphql/init.esm.js +2 -2
  54. package/dist/graphql/utils.cjs.js +17 -3
  55. package/dist/graphql/utils.d.mts +16 -16
  56. package/dist/graphql/utils.d.ts +16 -16
  57. package/dist/graphql/utils.esm.js +16 -2
  58. package/dist/index.d.mts +1 -1
  59. package/dist/index.d.ts +1 -1
  60. package/dist/socials/instagram/webhook.d.mts +2 -2
  61. package/dist/socials/instagram/webhook.d.ts +2 -2
  62. package/dist/utils/route.d.mts +20 -0
  63. package/dist/utils/route.d.ts +20 -0
  64. package/package.json +1 -1
@@ -5,11 +5,13 @@
5
5
  * The endpoint is read from `NEXT_PUBLIC_FILE_ENDPOINT` env var. The file is sent as multipart form data
6
6
  * along with a `type` string and optional JSON `data` for metadata.
7
7
  *
8
- * @returns A function `(file, type, data?) => Promise<FileUploadResponseType | null>`.
8
+ * @returns A function `(file, type, config?) => Promise<FileUploadResponseType | null>`.
9
9
  * - `file` — `File` or `Blob` to upload.
10
10
  * - `type` — String category (e.g. `"avatar"`, `"DealDocument"`); sent as form field `type`.
11
- * - `data` — Optional JSON-serializable object for metadata; sent as form field `data`.
12
- * Resolves to the JSON response `{ url, onUploadResponse }` or `null`.
11
+ * - `config` — Optional object with:
12
+ * - `data` JSON-serializable metadata object; sent as form field `data`.
13
+ * - `async` — If `true`, the upload is processed asynchronously on the server.
14
+ * Resolves to the JSON response `{ url, data }` or `null`.
13
15
  *
14
16
  * @example
15
17
  * ```tsx
@@ -23,9 +25,7 @@
23
25
  * setUploading(true);
24
26
  * try {
25
27
  * const result = await uploadFile(file, "DealDocument", {
26
- * dealId,
27
- * fileName: file.name,
28
- * category: "Contract",
28
+ * data: { dealId, fileName: file.name, category: "Contract" },
29
29
  * });
30
30
  * if (result?.url) {
31
31
  * console.log("Uploaded:", result.url);
@@ -50,7 +50,7 @@ declare const useFileUpload: () => (file: File | Blob, type: string, config?: {
50
50
  * Shape of the JSON response from the file upload PUT endpoint.
51
51
  *
52
52
  * @property url - The public S3 URL of the uploaded file.
53
- * @property onUploadResponse - The return value from the `onUpload` callback in `setupFileUpload`.
53
+ * @property data - The return value from the `onUpload` callback in `setupFileUpload`.
54
54
  *
55
55
  * @category File
56
56
  */
@@ -29,10 +29,10 @@ declare const tokenContext: (token?: string | null) => {
29
29
  * Uses `fetchPolicy: "no-cache"` by default to always get fresh data.
30
30
  *
31
31
  * @param query - A `TypedDocumentNode` for the query (e.g. from codegen or a `gql` template).
32
- * @param variables - Optional initial variables. Query fires automatically when this and token are set; change to refetch.
32
+ * @param variables - Optional initial variables (the `input` value). Automatically wrapped as `{ input: variables }` before sending. Query fires automatically when this and token are set; change to refetch.
33
33
  * @returns Tuple: `[refetch, result]`.
34
- * - `refetch(input)` — runs the query again with the given input (passed as `variables.input`).
35
- * - `result` — `{ data, loading, error }` from Apollo.
34
+ * - `refetch(input)` — runs the query again with the given input (wrapped as `variables.input`).
35
+ * - `result` — `{ data, loading, error, hasAuth }` from Apollo. `hasAuth` is `true` when an auth token is available.
36
36
  *
37
37
  * @example Lazy query (no initial variables, manually triggered):
38
38
  * ```tsx
@@ -92,8 +92,8 @@ declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocum
92
92
  * @param mutation - A `TypedDocumentNode` for the mutation (e.g. from codegen or a `gql` template).
93
93
  * @param options - Optional Apollo `MutationHookOptions` (e.g. `onCompleted`, `onError`, `refetchQueries`).
94
94
  * @returns Tuple: `[mutate, result]`.
95
- * - `mutate(input)` — runs the mutation with the given input. Returns a Promise with `{ data }`.
96
- * - `result` — `{ data, loading, error }` from Apollo.
95
+ * - `mutate(input)` — runs the mutation with the given input (wrapped as `variables.input`). Returns a Promise with `{ data }`.
96
+ * - `result` — `{ data, loading, error, hasAuth }` from Apollo. `hasAuth` is `true` when an auth token is available.
97
97
  *
98
98
  * @example
99
99
  * ```tsx
@@ -29,10 +29,10 @@ declare const tokenContext: (token?: string | null) => {
29
29
  * Uses `fetchPolicy: "no-cache"` by default to always get fresh data.
30
30
  *
31
31
  * @param query - A `TypedDocumentNode` for the query (e.g. from codegen or a `gql` template).
32
- * @param variables - Optional initial variables. Query fires automatically when this and token are set; change to refetch.
32
+ * @param variables - Optional initial variables (the `input` value). Automatically wrapped as `{ input: variables }` before sending. Query fires automatically when this and token are set; change to refetch.
33
33
  * @returns Tuple: `[refetch, result]`.
34
- * - `refetch(input)` — runs the query again with the given input (passed as `variables.input`).
35
- * - `result` — `{ data, loading, error }` from Apollo.
34
+ * - `refetch(input)` — runs the query again with the given input (wrapped as `variables.input`).
35
+ * - `result` — `{ data, loading, error, hasAuth }` from Apollo. `hasAuth` is `true` when an auth token is available.
36
36
  *
37
37
  * @example Lazy query (no initial variables, manually triggered):
38
38
  * ```tsx
@@ -92,8 +92,8 @@ declare function useAuthQuery<T, V extends OperationVariables>(query: TypedDocum
92
92
  * @param mutation - A `TypedDocumentNode` for the mutation (e.g. from codegen or a `gql` template).
93
93
  * @param options - Optional Apollo `MutationHookOptions` (e.g. `onCompleted`, `onError`, `refetchQueries`).
94
94
  * @returns Tuple: `[mutate, result]`.
95
- * - `mutate(input)` — runs the mutation with the given input. Returns a Promise with `{ data }`.
96
- * - `result` — `{ data, loading, error }` from Apollo.
95
+ * - `mutate(input)` — runs the mutation with the given input (wrapped as `variables.input`). Returns a Promise with `{ data }`.
96
+ * - `result` — `{ data, loading, error, hasAuth }` from Apollo. `hasAuth` is `true` when an auth token is available.
97
97
  *
98
98
  * @example
99
99
  * ```tsx
@@ -542,8 +542,8 @@ __export(graphql_exports, {
542
542
  GQLError: () => GQLError,
543
543
  QueryLibrary: () => QueryLibrary,
544
544
  field: () => field,
545
- initGraphQLServer: () => initGraphQLServer,
546
- query: () => query
545
+ resolver: () => resolver,
546
+ setupGraphQL: () => setupGraphQL
547
547
  });
548
548
  module.exports = __toCommonJS(graphql_exports);
549
549
 
@@ -711,7 +711,7 @@ var getContext = (req) => {
711
711
  };
712
712
 
713
713
  // src/graphql/init.ts
714
- async function initGraphQLServer({
714
+ async function setupGraphQL({
715
715
  authChecker,
716
716
  resolvers,
717
717
  plugins,
@@ -756,7 +756,7 @@ async function initGraphQLServer({
756
756
  var import_headers2 = require("next/headers");
757
757
  var import_react = require("react");
758
758
  var import_type_graphql2 = require("type-graphql");
759
- function query(fn, options) {
759
+ function resolver(fn, options) {
760
760
  return {
761
761
  ...options,
762
762
  fn,
@@ -829,6 +829,20 @@ function QueryLibrary(queries) {
829
829
  GeneratedResolver = __decorateClass([
830
830
  (0, import_type_graphql2.Resolver)()
831
831
  ], GeneratedResolver);
832
+ const hasQuery = Object.values(queries).some((def) => !def.mutation);
833
+ if (!hasQuery) {
834
+ Object.defineProperty(GeneratedResolver.prototype, "_health", {
835
+ value: async function() {
836
+ return true;
837
+ },
838
+ writable: false
839
+ });
840
+ const descriptor = Object.getOwnPropertyDescriptor(
841
+ GeneratedResolver.prototype,
842
+ "_health"
843
+ );
844
+ (0, import_type_graphql2.Query)(() => Boolean)(GeneratedResolver.prototype, "_health", descriptor);
845
+ }
832
846
  for (const key in queries) {
833
847
  const def = queries[key];
834
848
  if (!def) continue;
@@ -915,6 +929,6 @@ function FieldLibrary(type, queries) {
915
929
  GQLError,
916
930
  QueryLibrary,
917
931
  field,
918
- initGraphQLServer,
919
- query
932
+ resolver,
933
+ setupGraphQL
920
934
  });
@@ -1,7 +1,7 @@
1
1
  export { GQLError } from './errors.mjs';
2
- export { initGraphQLServer } from './init.mjs';
2
+ export { setupGraphQL } from './init.mjs';
3
3
  export { AuthorizedContext, Context } from './types.mjs';
4
- export { FieldLibrary, FieldResolverDefinition, FieldResponseType, QueryDefinition, QueryLibrary, QueryResponseType, field, query } from './utils.mjs';
4
+ export { FieldLibrary, FieldResolverDefinition, FieldResponseType, QueryDefinition, QueryLibrary, QueryResponseType, field, resolver } from './utils.mjs';
5
5
  import 'graphql/error';
6
6
  import '@apollo/server';
7
7
  import 'next/server';
@@ -1,7 +1,7 @@
1
1
  export { GQLError } from './errors.js';
2
- export { initGraphQLServer } from './init.js';
2
+ export { setupGraphQL } from './init.js';
3
3
  export { AuthorizedContext, Context } from './types.js';
4
- export { FieldLibrary, FieldResolverDefinition, FieldResponseType, QueryDefinition, QueryLibrary, QueryResponseType, field, query } from './utils.js';
4
+ export { FieldLibrary, FieldResolverDefinition, FieldResponseType, QueryDefinition, QueryLibrary, QueryResponseType, field, resolver } from './utils.js';
5
5
  import 'graphql/error';
6
6
  import '@apollo/server';
7
7
  import 'next/server';
@@ -698,7 +698,7 @@ var getContext = (req) => {
698
698
  };
699
699
 
700
700
  // src/graphql/init.ts
701
- async function initGraphQLServer({
701
+ async function setupGraphQL({
702
702
  authChecker,
703
703
  resolvers,
704
704
  plugins,
@@ -752,7 +752,7 @@ import {
752
752
  Resolver,
753
753
  Root
754
754
  } from "type-graphql";
755
- function query(fn, options) {
755
+ function resolver(fn, options) {
756
756
  return {
757
757
  ...options,
758
758
  fn,
@@ -825,6 +825,20 @@ function QueryLibrary(queries) {
825
825
  GeneratedResolver = __decorateClass([
826
826
  Resolver()
827
827
  ], GeneratedResolver);
828
+ const hasQuery = Object.values(queries).some((def) => !def.mutation);
829
+ if (!hasQuery) {
830
+ Object.defineProperty(GeneratedResolver.prototype, "_health", {
831
+ value: async function() {
832
+ return true;
833
+ },
834
+ writable: false
835
+ });
836
+ const descriptor = Object.getOwnPropertyDescriptor(
837
+ GeneratedResolver.prototype,
838
+ "_health"
839
+ );
840
+ Query(() => Boolean)(GeneratedResolver.prototype, "_health", descriptor);
841
+ }
828
842
  for (const key in queries) {
829
843
  const def = queries[key];
830
844
  if (!def) continue;
@@ -910,6 +924,6 @@ export {
910
924
  GQLError,
911
925
  QueryLibrary,
912
926
  field,
913
- initGraphQLServer,
914
- query
927
+ resolver,
928
+ setupGraphQL
915
929
  };
@@ -20,7 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/graphql/init.ts
21
21
  var init_exports = {};
22
22
  __export(init_exports, {
23
- initGraphQLServer: () => initGraphQLServer
23
+ setupGraphQL: () => setupGraphQL
24
24
  });
25
25
  module.exports = __toCommonJS(init_exports);
26
26
  var import_reflect_metadata = require("reflect-metadata");
@@ -164,7 +164,7 @@ var getContext = (req) => {
164
164
  };
165
165
 
166
166
  // src/graphql/init.ts
167
- async function initGraphQLServer({
167
+ async function setupGraphQL({
168
168
  authChecker,
169
169
  resolvers,
170
170
  plugins,
@@ -206,5 +206,5 @@ async function initGraphQLServer({
206
206
  }
207
207
  // Annotate the CommonJS export names for ESM import in node:
208
208
  0 && (module.exports = {
209
- initGraphQLServer
209
+ setupGraphQL
210
210
  });
@@ -24,18 +24,18 @@ import { AuthChecker, NonEmptyArray } from 'type-graphql';
24
24
  * @example
25
25
  * ```ts
26
26
  * // app/api/(graphql)/route.ts
27
- * import { initGraphQLServer } from "naystack/graphql";
27
+ * import { setupGraphQL } from "naystack/graphql";
28
28
  * import { UserResolvers, UserFieldResolvers } from "./User/graphql";
29
29
  * import { ChatResolvers } from "./Chat/graphql";
30
30
  *
31
- * export const { GET, POST } = await initGraphQLServer({
31
+ * export const { GET, POST } = await setupGraphQL({
32
32
  * resolvers: [UserResolvers, UserFieldResolvers, ChatResolvers],
33
33
  * });
34
34
  * ```
35
35
  *
36
36
  * @category GraphQL
37
37
  */
38
- declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext: overrideGetContext, allowedOrigins, }: {
38
+ declare function setupGraphQL({ authChecker, resolvers, plugins, getContext: overrideGetContext, allowedOrigins, }: {
39
39
  authChecker?: AuthChecker<any>;
40
40
  resolvers: NonEmptyArray<Function>;
41
41
  plugins?: ApolloServerPlugin[];
@@ -47,4 +47,4 @@ declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext
47
47
  OPTIONS: () => NextResponse<unknown>;
48
48
  }>;
49
49
 
50
- export { initGraphQLServer };
50
+ export { setupGraphQL };
@@ -24,18 +24,18 @@ import { AuthChecker, NonEmptyArray } from 'type-graphql';
24
24
  * @example
25
25
  * ```ts
26
26
  * // app/api/(graphql)/route.ts
27
- * import { initGraphQLServer } from "naystack/graphql";
27
+ * import { setupGraphQL } from "naystack/graphql";
28
28
  * import { UserResolvers, UserFieldResolvers } from "./User/graphql";
29
29
  * import { ChatResolvers } from "./Chat/graphql";
30
30
  *
31
- * export const { GET, POST } = await initGraphQLServer({
31
+ * export const { GET, POST } = await setupGraphQL({
32
32
  * resolvers: [UserResolvers, UserFieldResolvers, ChatResolvers],
33
33
  * });
34
34
  * ```
35
35
  *
36
36
  * @category GraphQL
37
37
  */
38
- declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext: overrideGetContext, allowedOrigins, }: {
38
+ declare function setupGraphQL({ authChecker, resolvers, plugins, getContext: overrideGetContext, allowedOrigins, }: {
39
39
  authChecker?: AuthChecker<any>;
40
40
  resolvers: NonEmptyArray<Function>;
41
41
  plugins?: ApolloServerPlugin[];
@@ -47,4 +47,4 @@ declare function initGraphQLServer({ authChecker, resolvers, plugins, getContext
47
47
  OPTIONS: () => NextResponse<unknown>;
48
48
  }>;
49
49
 
50
- export { initGraphQLServer };
50
+ export { setupGraphQL };
@@ -145,7 +145,7 @@ var getContext = (req) => {
145
145
  };
146
146
 
147
147
  // src/graphql/init.ts
148
- async function initGraphQLServer({
148
+ async function setupGraphQL({
149
149
  authChecker,
150
150
  resolvers,
151
151
  plugins,
@@ -186,5 +186,5 @@ async function initGraphQLServer({
186
186
  };
187
187
  }
188
188
  export {
189
- initGraphQLServer
189
+ setupGraphQL
190
190
  };
@@ -31,7 +31,7 @@ __export(utils_exports, {
31
31
  FieldLibrary: () => FieldLibrary,
32
32
  QueryLibrary: () => QueryLibrary,
33
33
  field: () => field,
34
- query: () => query
34
+ resolver: () => resolver
35
35
  });
36
36
  module.exports = __toCommonJS(utils_exports);
37
37
  var import_headers2 = require("next/headers");
@@ -113,7 +113,7 @@ function getUserIdFromRefreshToken(refreshToken) {
113
113
  }
114
114
 
115
115
  // src/graphql/utils.ts
116
- function query(fn, options) {
116
+ function resolver(fn, options) {
117
117
  return {
118
118
  ...options,
119
119
  fn,
@@ -186,6 +186,20 @@ function QueryLibrary(queries) {
186
186
  GeneratedResolver = __decorateClass([
187
187
  (0, import_type_graphql.Resolver)()
188
188
  ], GeneratedResolver);
189
+ const hasQuery = Object.values(queries).some((def) => !def.mutation);
190
+ if (!hasQuery) {
191
+ Object.defineProperty(GeneratedResolver.prototype, "_health", {
192
+ value: async function() {
193
+ return true;
194
+ },
195
+ writable: false
196
+ });
197
+ const descriptor = Object.getOwnPropertyDescriptor(
198
+ GeneratedResolver.prototype,
199
+ "_health"
200
+ );
201
+ (0, import_type_graphql.Query)(() => Boolean)(GeneratedResolver.prototype, "_health", descriptor);
202
+ }
189
203
  for (const key in queries) {
190
204
  const def = queries[key];
191
205
  if (!def) continue;
@@ -271,5 +285,5 @@ function FieldLibrary(type, queries) {
271
285
  FieldLibrary,
272
286
  QueryLibrary,
273
287
  field,
274
- query
288
+ resolver
275
289
  });
@@ -35,7 +35,7 @@ interface BaseDefinition<T, U, IsAuth extends boolean = false, OutputNullable ex
35
35
  authorized?: IsAuth;
36
36
  }
37
37
  /**
38
- * Full query/mutation definition returned by {@link query}. Contains the resolver function,
38
+ * Full query/mutation definition returned by {@link resolver}. Contains the resolver function,
39
39
  * plus `.call()` and `.authCall()` for direct server-side invocation.
40
40
  *
41
41
  * @category GraphQL
@@ -50,7 +50,7 @@ interface QueryDefinition<T, U, IsAuth extends boolean = false, OutputNullable e
50
50
  }
51
51
  /**
52
52
  * Defines a type-graphql query or mutation with typed input/output and optional auth.
53
- * Use with {@link QueryLibrary} to build resolver classes for `initGraphQLServer`.
53
+ * Use with {@link QueryLibrary} to build resolver classes for `setupGraphQL`.
54
54
  *
55
55
  * Each query definition gets `.call(data)` and `.authCall(data)` methods for direct server-side invocation
56
56
  * (e.g. in Server Components or other resolvers). Both are cached via React's `cache()`.
@@ -69,9 +69,9 @@ interface QueryDefinition<T, U, IsAuth extends boolean = false, OutputNullable e
69
69
  *
70
70
  * @example Simple query (no input, nullable output):
71
71
  * ```ts
72
- * import { query } from "naystack/graphql";
72
+ * import { resolver } from "naystack/graphql";
73
73
  *
74
- * export default query(
74
+ * export default resolver(
75
75
  * async (ctx) => {
76
76
  * if (!ctx.userId) return null;
77
77
  * const [user] = await db.select().from(UserTable).where(eq(UserTable.id, ctx.userId));
@@ -83,7 +83,7 @@ interface QueryDefinition<T, U, IsAuth extends boolean = false, OutputNullable e
83
83
  *
84
84
  * @example Mutation with input and authorization:
85
85
  * ```ts
86
- * export default query(
86
+ * export default resolver(
87
87
  * async (ctx, input: SubmitFeedbackInput) => {
88
88
  * await db.insert(FeedbackTable).values({ userId: ctx.userId, score: input.score, text: input.text });
89
89
  * return true;
@@ -100,7 +100,7 @@ interface QueryDefinition<T, U, IsAuth extends boolean = false, OutputNullable e
100
100
  *
101
101
  * @category GraphQL
102
102
  */
103
- declare function query<T, U, IsAuth extends boolean = false, OutputNullable extends boolean = false, InputNullable extends boolean = false, R extends Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>> = Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>>>(fn: (ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithNullability<U, InputNullable, false>) => R, options: Omit<QueryDefinition<T, U, IsAuth, OutputNullable, InputNullable, R>, "fn" | "authCall" | "call">): QueryDefinition<T, U, IsAuth, OutputNullable, InputNullable, R>;
103
+ declare function resolver<T, U, IsAuth extends boolean = false, OutputNullable extends boolean = false, InputNullable extends boolean = false, R extends Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>> = Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>>>(fn: (ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithNullability<U, InputNullable, false>) => R, options: Omit<QueryDefinition<T, U, IsAuth, OutputNullable, InputNullable, R>, "fn" | "authCall" | "call">): QueryDefinition<T, U, IsAuth, OutputNullable, InputNullable, R>;
104
104
  /**
105
105
  * Full field resolver definition returned by {@link field}. Contains the resolver function,
106
106
  * plus `.call()` and `.authCall()` for direct server-side invocation.
@@ -118,13 +118,13 @@ interface FieldResolverDefinition<T, U, Root, IsAuth extends boolean = false, Ou
118
118
  * Defines a type-graphql field resolver with typed root, context, and input.
119
119
  * Use with {@link FieldLibrary} to attach computed fields to a parent GraphQL type.
120
120
  *
121
- * Like `query()`, each field definition gets `.call(root, data)` and `.authCall(root, data)` for server-side invocation.
121
+ * Like `resolver()`, each field definition gets `.call(root, data)` and `.authCall(root, data)` for server-side invocation.
122
122
  *
123
123
  * @param fn - Resolver function: `(root, ctx, data) => result`.
124
124
  * - `root` is the parent object (e.g. the `User` row from the database).
125
125
  * - `ctx` is `Context` (or `AuthorizedContext` when `authorized: true`).
126
126
  * - `data` is the optional typed input argument.
127
- * @param options - Configuration (same as `query()` but without `mutation`).
127
+ * @param options - Configuration (same as `resolver()` but without `mutation`).
128
128
  * @returns A `FieldResolverDefinition` with `.call` and `.authCall` for server-side invocation.
129
129
  *
130
130
  * @example
@@ -159,14 +159,14 @@ interface FieldResolverDefinition<T, U, Root, IsAuth extends boolean = false, Ou
159
159
  */
160
160
  declare function field<T, U, IsAuth extends boolean, Root, OutputNullable extends boolean = false, InputNullable extends boolean = false, R extends Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>> = Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>>>(fn: (root: Root, ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithNullability<U, InputNullable, false>) => R, options: Omit<FieldResolverDefinition<T, U, Root, IsAuth, OutputNullable, InputNullable, R>, "fn" | "authCall" | "call">): FieldResolverDefinition<T, U, Root, IsAuth, OutputNullable, InputNullable, R>;
161
161
  /**
162
- * Builds a type-graphql `@Resolver` class from a map of query/mutation definitions created with {@link query}.
162
+ * Builds a type-graphql `@Resolver` class from a map of query/mutation definitions created with {@link resolver}.
163
163
  * Each key in the `queries` object becomes a Query or Mutation field on the GraphQL schema.
164
164
  *
165
- * Pass the returned class in the `resolvers` array of `initGraphQLServer`.
165
+ * Pass the returned class in the `resolvers` array of `setupGraphQL`.
166
166
  *
167
- * @param queries - Object mapping GraphQL field names to `QueryDefinition`s (from `query()`).
167
+ * @param queries - Object mapping GraphQL field names to `QueryDefinition`s (from `resolver()`).
168
168
  * Each key becomes the field name in the schema. Mutations are determined by `{ mutation: true }` in the definition.
169
- * @returns A `@Resolver` class suitable for `initGraphQLServer`.
169
+ * @returns A `@Resolver` class suitable for `setupGraphQL`.
170
170
  *
171
171
  * @example
172
172
  * ```ts
@@ -191,12 +191,12 @@ declare function QueryLibrary<T extends Record<string, QueryDefinition<any, any,
191
191
  * Builds a type-graphql `@Resolver(() => type)` class that resolves computed fields on a parent GraphQL type.
192
192
  * Each key in the `queries` object becomes a `@FieldResolver` on that type.
193
193
  *
194
- * Pass the returned class in the `resolvers` array of `initGraphQLServer`.
194
+ * Pass the returned class in the `resolvers` array of `setupGraphQL`.
195
195
  *
196
196
  * @typeParam X - The database/plain type of the parent object (e.g. `UserDB`).
197
197
  * @param type - The parent GraphQL type class (e.g. `User`). Must be a `@ObjectType` class.
198
198
  * @param queries - Object mapping field names to `FieldResolverDefinition`s (from `field()`).
199
- * @returns A `@Resolver` class for the given type; pass it in `initGraphQLServer`'s resolvers array.
199
+ * @returns A `@Resolver` class for the given type; pass it in `setupGraphQL`'s resolvers array.
200
200
  *
201
201
  * @example
202
202
  * ```ts
@@ -229,7 +229,7 @@ declare function FieldLibrary<X extends object, T extends Record<string, FieldRe
229
229
  * Infers the TypeScript return type of a query definition's `.call()` method.
230
230
  * Use this to type component props that receive query results, ensuring full type safety.
231
231
  *
232
- * @typeParam T - A `QueryDefinition` (the default export from a resolver file created with `query()`).
232
+ * @typeParam T - A `QueryDefinition` (the default export from a resolver file created with `resolver()`).
233
233
  *
234
234
  * @example
235
235
  * ```ts
@@ -264,4 +264,4 @@ type QueryResponseType<T extends QueryDefinition<any, any, any, any, any, any>>
264
264
  */
265
265
  type FieldResponseType<T extends FieldResolverDefinition<any, any, any, any, any, any, any>> = Awaited<ReturnType<T["call"]>>;
266
266
 
267
- export { FieldLibrary, type FieldResolverDefinition, type FieldResponseType, type QueryDefinition, QueryLibrary, type QueryResponseType, field, query };
267
+ export { FieldLibrary, type FieldResolverDefinition, type FieldResponseType, type QueryDefinition, QueryLibrary, type QueryResponseType, field, resolver };
@@ -35,7 +35,7 @@ interface BaseDefinition<T, U, IsAuth extends boolean = false, OutputNullable ex
35
35
  authorized?: IsAuth;
36
36
  }
37
37
  /**
38
- * Full query/mutation definition returned by {@link query}. Contains the resolver function,
38
+ * Full query/mutation definition returned by {@link resolver}. Contains the resolver function,
39
39
  * plus `.call()` and `.authCall()` for direct server-side invocation.
40
40
  *
41
41
  * @category GraphQL
@@ -50,7 +50,7 @@ interface QueryDefinition<T, U, IsAuth extends boolean = false, OutputNullable e
50
50
  }
51
51
  /**
52
52
  * Defines a type-graphql query or mutation with typed input/output and optional auth.
53
- * Use with {@link QueryLibrary} to build resolver classes for `initGraphQLServer`.
53
+ * Use with {@link QueryLibrary} to build resolver classes for `setupGraphQL`.
54
54
  *
55
55
  * Each query definition gets `.call(data)` and `.authCall(data)` methods for direct server-side invocation
56
56
  * (e.g. in Server Components or other resolvers). Both are cached via React's `cache()`.
@@ -69,9 +69,9 @@ interface QueryDefinition<T, U, IsAuth extends boolean = false, OutputNullable e
69
69
  *
70
70
  * @example Simple query (no input, nullable output):
71
71
  * ```ts
72
- * import { query } from "naystack/graphql";
72
+ * import { resolver } from "naystack/graphql";
73
73
  *
74
- * export default query(
74
+ * export default resolver(
75
75
  * async (ctx) => {
76
76
  * if (!ctx.userId) return null;
77
77
  * const [user] = await db.select().from(UserTable).where(eq(UserTable.id, ctx.userId));
@@ -83,7 +83,7 @@ interface QueryDefinition<T, U, IsAuth extends boolean = false, OutputNullable e
83
83
  *
84
84
  * @example Mutation with input and authorization:
85
85
  * ```ts
86
- * export default query(
86
+ * export default resolver(
87
87
  * async (ctx, input: SubmitFeedbackInput) => {
88
88
  * await db.insert(FeedbackTable).values({ userId: ctx.userId, score: input.score, text: input.text });
89
89
  * return true;
@@ -100,7 +100,7 @@ interface QueryDefinition<T, U, IsAuth extends boolean = false, OutputNullable e
100
100
  *
101
101
  * @category GraphQL
102
102
  */
103
- declare function query<T, U, IsAuth extends boolean = false, OutputNullable extends boolean = false, InputNullable extends boolean = false, R extends Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>> = Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>>>(fn: (ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithNullability<U, InputNullable, false>) => R, options: Omit<QueryDefinition<T, U, IsAuth, OutputNullable, InputNullable, R>, "fn" | "authCall" | "call">): QueryDefinition<T, U, IsAuth, OutputNullable, InputNullable, R>;
103
+ declare function resolver<T, U, IsAuth extends boolean = false, OutputNullable extends boolean = false, InputNullable extends boolean = false, R extends Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>> = Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>>>(fn: (ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithNullability<U, InputNullable, false>) => R, options: Omit<QueryDefinition<T, U, IsAuth, OutputNullable, InputNullable, R>, "fn" | "authCall" | "call">): QueryDefinition<T, U, IsAuth, OutputNullable, InputNullable, R>;
104
104
  /**
105
105
  * Full field resolver definition returned by {@link field}. Contains the resolver function,
106
106
  * plus `.call()` and `.authCall()` for direct server-side invocation.
@@ -118,13 +118,13 @@ interface FieldResolverDefinition<T, U, Root, IsAuth extends boolean = false, Ou
118
118
  * Defines a type-graphql field resolver with typed root, context, and input.
119
119
  * Use with {@link FieldLibrary} to attach computed fields to a parent GraphQL type.
120
120
  *
121
- * Like `query()`, each field definition gets `.call(root, data)` and `.authCall(root, data)` for server-side invocation.
121
+ * Like `resolver()`, each field definition gets `.call(root, data)` and `.authCall(root, data)` for server-side invocation.
122
122
  *
123
123
  * @param fn - Resolver function: `(root, ctx, data) => result`.
124
124
  * - `root` is the parent object (e.g. the `User` row from the database).
125
125
  * - `ctx` is `Context` (or `AuthorizedContext` when `authorized: true`).
126
126
  * - `data` is the optional typed input argument.
127
- * @param options - Configuration (same as `query()` but without `mutation`).
127
+ * @param options - Configuration (same as `resolver()` but without `mutation`).
128
128
  * @returns A `FieldResolverDefinition` with `.call` and `.authCall` for server-side invocation.
129
129
  *
130
130
  * @example
@@ -159,14 +159,14 @@ interface FieldResolverDefinition<T, U, Root, IsAuth extends boolean = false, Ou
159
159
  */
160
160
  declare function field<T, U, IsAuth extends boolean, Root, OutputNullable extends boolean = false, InputNullable extends boolean = false, R extends Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>> = Promisify<ParsedGQLTypeWithNullability<T, OutputNullable, true>>>(fn: (root: Root, ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithNullability<U, InputNullable, false>) => R, options: Omit<FieldResolverDefinition<T, U, Root, IsAuth, OutputNullable, InputNullable, R>, "fn" | "authCall" | "call">): FieldResolverDefinition<T, U, Root, IsAuth, OutputNullable, InputNullable, R>;
161
161
  /**
162
- * Builds a type-graphql `@Resolver` class from a map of query/mutation definitions created with {@link query}.
162
+ * Builds a type-graphql `@Resolver` class from a map of query/mutation definitions created with {@link resolver}.
163
163
  * Each key in the `queries` object becomes a Query or Mutation field on the GraphQL schema.
164
164
  *
165
- * Pass the returned class in the `resolvers` array of `initGraphQLServer`.
165
+ * Pass the returned class in the `resolvers` array of `setupGraphQL`.
166
166
  *
167
- * @param queries - Object mapping GraphQL field names to `QueryDefinition`s (from `query()`).
167
+ * @param queries - Object mapping GraphQL field names to `QueryDefinition`s (from `resolver()`).
168
168
  * Each key becomes the field name in the schema. Mutations are determined by `{ mutation: true }` in the definition.
169
- * @returns A `@Resolver` class suitable for `initGraphQLServer`.
169
+ * @returns A `@Resolver` class suitable for `setupGraphQL`.
170
170
  *
171
171
  * @example
172
172
  * ```ts
@@ -191,12 +191,12 @@ declare function QueryLibrary<T extends Record<string, QueryDefinition<any, any,
191
191
  * Builds a type-graphql `@Resolver(() => type)` class that resolves computed fields on a parent GraphQL type.
192
192
  * Each key in the `queries` object becomes a `@FieldResolver` on that type.
193
193
  *
194
- * Pass the returned class in the `resolvers` array of `initGraphQLServer`.
194
+ * Pass the returned class in the `resolvers` array of `setupGraphQL`.
195
195
  *
196
196
  * @typeParam X - The database/plain type of the parent object (e.g. `UserDB`).
197
197
  * @param type - The parent GraphQL type class (e.g. `User`). Must be a `@ObjectType` class.
198
198
  * @param queries - Object mapping field names to `FieldResolverDefinition`s (from `field()`).
199
- * @returns A `@Resolver` class for the given type; pass it in `initGraphQLServer`'s resolvers array.
199
+ * @returns A `@Resolver` class for the given type; pass it in `setupGraphQL`'s resolvers array.
200
200
  *
201
201
  * @example
202
202
  * ```ts
@@ -229,7 +229,7 @@ declare function FieldLibrary<X extends object, T extends Record<string, FieldRe
229
229
  * Infers the TypeScript return type of a query definition's `.call()` method.
230
230
  * Use this to type component props that receive query results, ensuring full type safety.
231
231
  *
232
- * @typeParam T - A `QueryDefinition` (the default export from a resolver file created with `query()`).
232
+ * @typeParam T - A `QueryDefinition` (the default export from a resolver file created with `resolver()`).
233
233
  *
234
234
  * @example
235
235
  * ```ts
@@ -264,4 +264,4 @@ type QueryResponseType<T extends QueryDefinition<any, any, any, any, any, any>>
264
264
  */
265
265
  type FieldResponseType<T extends FieldResolverDefinition<any, any, any, any, any, any, any>> = Awaited<ReturnType<T["call"]>>;
266
266
 
267
- export { FieldLibrary, type FieldResolverDefinition, type FieldResponseType, type QueryDefinition, QueryLibrary, type QueryResponseType, field, query };
267
+ export { FieldLibrary, type FieldResolverDefinition, type FieldResponseType, type QueryDefinition, QueryLibrary, type QueryResponseType, field, resolver };
@@ -98,7 +98,7 @@ function getUserIdFromRefreshToken(refreshToken) {
98
98
  }
99
99
 
100
100
  // src/graphql/utils.ts
101
- function query(fn, options) {
101
+ function resolver(fn, options) {
102
102
  return {
103
103
  ...options,
104
104
  fn,
@@ -171,6 +171,20 @@ function QueryLibrary(queries) {
171
171
  GeneratedResolver = __decorateClass([
172
172
  Resolver()
173
173
  ], GeneratedResolver);
174
+ const hasQuery = Object.values(queries).some((def) => !def.mutation);
175
+ if (!hasQuery) {
176
+ Object.defineProperty(GeneratedResolver.prototype, "_health", {
177
+ value: async function() {
178
+ return true;
179
+ },
180
+ writable: false
181
+ });
182
+ const descriptor = Object.getOwnPropertyDescriptor(
183
+ GeneratedResolver.prototype,
184
+ "_health"
185
+ );
186
+ Query(() => Boolean)(GeneratedResolver.prototype, "_health", descriptor);
187
+ }
174
188
  for (const key in queries) {
175
189
  const def = queries[key];
176
190
  if (!def) continue;
@@ -255,5 +269,5 @@ export {
255
269
  FieldLibrary,
256
270
  QueryLibrary,
257
271
  field,
258
- query
272
+ resolver
259
273
  };
package/dist/index.d.mts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Use subpath imports for the specific module you need:
5
5
  * - `naystack/auth` — Email/Google/Instagram authentication
6
6
  * - `naystack/auth/email/client` — Client-side auth hooks (useLogin, useSignUp, etc.)
7
- * - `naystack/graphql` — GraphQL server: query, field, QueryLibrary, FieldLibrary, initGraphQLServer
7
+ * - `naystack/graphql` — GraphQL server: resolver, field, QueryLibrary, FieldLibrary, setupGraphQL
8
8
  * - `naystack/graphql/client` — Client-side GraphQL hooks (useAuthQuery, useAuthMutation, ApolloWrapper)
9
9
  * - `naystack/graphql/server` — Server-side GraphQL utilities (Injector, query)
10
10
  * - `naystack/file` — S3 file upload setup
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Use subpath imports for the specific module you need:
5
5
  * - `naystack/auth` — Email/Google/Instagram authentication
6
6
  * - `naystack/auth/email/client` — Client-side auth hooks (useLogin, useSignUp, etc.)
7
- * - `naystack/graphql` — GraphQL server: query, field, QueryLibrary, FieldLibrary, initGraphQLServer
7
+ * - `naystack/graphql` — GraphQL server: resolver, field, QueryLibrary, FieldLibrary, setupGraphQL
8
8
  * - `naystack/graphql/client` — Client-side GraphQL hooks (useAuthQuery, useAuthMutation, ApolloWrapper)
9
9
  * - `naystack/graphql/server` — Server-side GraphQL utilities (Injector, query)
10
10
  * - `naystack/file` — S3 file upload setup