naystack 1.7.0 → 1.7.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.
Files changed (92) hide show
  1. package/README.md +45 -28
  2. package/dist/auth/client.cjs.js +230 -0
  3. package/dist/auth/client.d.mts +3 -0
  4. package/dist/auth/client.d.ts +3 -0
  5. package/dist/auth/client.esm.js +190 -0
  6. package/dist/auth/email/client.cjs.js +6 -2
  7. package/dist/auth/email/client.d.mts +34 -12
  8. package/dist/auth/email/client.d.ts +34 -12
  9. package/dist/auth/email/client.esm.js +6 -2
  10. package/dist/auth/email/index.cjs.js +11 -6
  11. package/dist/auth/email/index.d.mts +8 -7
  12. package/dist/auth/email/index.d.ts +8 -7
  13. package/dist/auth/email/index.esm.js +9 -5
  14. package/dist/auth/email/{server.cjs.js → next.cjs.js} +16 -7
  15. package/dist/auth/email/next.d.mts +7 -0
  16. package/dist/auth/email/next.d.ts +7 -0
  17. package/dist/auth/email/{server.esm.js → next.esm.js} +8 -4
  18. package/dist/auth/email/routes/delete.d.mts +3 -3
  19. package/dist/auth/email/routes/delete.d.ts +3 -3
  20. package/dist/auth/email/routes/get.d.mts +3 -3
  21. package/dist/auth/email/routes/get.d.ts +3 -3
  22. package/dist/auth/email/routes/post.d.mts +3 -3
  23. package/dist/auth/email/routes/post.d.ts +3 -3
  24. package/dist/auth/email/routes/put.d.mts +3 -3
  25. package/dist/auth/email/routes/put.d.ts +3 -3
  26. package/dist/auth/email/token.cjs.js +3 -3
  27. package/dist/auth/email/token.d.mts +2 -2
  28. package/dist/auth/email/token.d.ts +2 -2
  29. package/dist/auth/email/token.esm.js +3 -3
  30. package/dist/auth/email/types.d.mts +5 -4
  31. package/dist/auth/email/types.d.ts +5 -4
  32. package/dist/auth/email/utils.d.mts +3 -3
  33. package/dist/auth/email/utils.d.ts +3 -3
  34. package/dist/auth/google/get.d.mts +3 -3
  35. package/dist/auth/google/get.d.ts +3 -3
  36. package/dist/auth/google/index.cjs.js +3 -3
  37. package/dist/auth/google/index.d.mts +7 -7
  38. package/dist/auth/google/index.d.ts +7 -7
  39. package/dist/auth/google/index.esm.js +2 -2
  40. package/dist/auth/index.cjs.js +25 -25
  41. package/dist/auth/index.d.mts +5 -4
  42. package/dist/auth/index.d.ts +5 -4
  43. package/dist/auth/index.esm.js +12 -12
  44. package/dist/auth/instagram/index.cjs.js +6 -6
  45. package/dist/auth/instagram/index.d.mts +8 -9
  46. package/dist/auth/instagram/index.d.ts +8 -9
  47. package/dist/auth/instagram/index.esm.js +5 -5
  48. package/dist/auth/instagram/route.cjs.js +3 -3
  49. package/dist/auth/instagram/route.d.mts +3 -3
  50. package/dist/auth/instagram/route.d.ts +3 -3
  51. package/dist/auth/instagram/route.esm.js +3 -3
  52. package/dist/file/client.cjs.js +1 -1
  53. package/dist/file/client.d.mts +7 -7
  54. package/dist/file/client.d.ts +7 -7
  55. package/dist/file/client.esm.js +1 -1
  56. package/dist/graphql/client.cjs.js +1 -1
  57. package/dist/graphql/client.d.mts +5 -5
  58. package/dist/graphql/client.d.ts +5 -5
  59. package/dist/graphql/client.esm.js +1 -1
  60. package/dist/graphql/index.cjs.js +94 -6
  61. package/dist/graphql/index.d.mts +7 -2
  62. package/dist/graphql/index.d.ts +7 -2
  63. package/dist/graphql/index.esm.js +97 -4
  64. package/dist/graphql/init.cjs.js +3 -3
  65. package/dist/graphql/init.d.mts +4 -4
  66. package/dist/graphql/init.d.ts +4 -4
  67. package/dist/graphql/init.esm.js +2 -2
  68. package/dist/graphql/utils.cjs.js +17 -3
  69. package/dist/graphql/utils.d.mts +16 -16
  70. package/dist/graphql/utils.d.ts +16 -16
  71. package/dist/graphql/utils.esm.js +16 -2
  72. package/dist/index.d.mts +2 -2
  73. package/dist/index.d.ts +2 -2
  74. package/dist/socials/instagram/webhook.d.mts +2 -2
  75. package/dist/socials/instagram/webhook.d.ts +2 -2
  76. package/dist/{client → utils/client}/hooks.cjs.js +1 -1
  77. package/dist/{client → utils/client}/hooks.esm.js +1 -1
  78. package/dist/{client → utils/client}/index.cjs.js +3 -3
  79. package/dist/{client → utils/client}/index.esm.js +2 -2
  80. package/dist/{client → utils/client}/seo.cjs.js +2 -2
  81. package/dist/{client → utils/client}/seo.esm.js +1 -1
  82. package/dist/utils/route.d.mts +20 -0
  83. package/dist/utils/route.d.ts +20 -0
  84. package/package.json +17 -32
  85. package/dist/auth/email/server.d.mts +0 -5
  86. package/dist/auth/email/server.d.ts +0 -5
  87. /package/dist/{client → utils/client}/hooks.d.mts +0 -0
  88. /package/dist/{client → utils/client}/hooks.d.ts +0 -0
  89. /package/dist/{client → utils/client}/index.d.mts +0 -0
  90. /package/dist/{client → utils/client}/index.d.ts +0 -0
  91. /package/dist/{client → utils/client}/seo.d.mts +0 -0
  92. /package/dist/{client → utils/client}/seo.d.ts +0 -0
@@ -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;
@@ -905,11 +919,90 @@ function FieldLibrary(type, queries) {
905
919
  }
906
920
  return GeneratedResolver;
907
921
  }
922
+
923
+ // src/graphql/server.tsx
924
+ import {
925
+ ApolloClient,
926
+ HttpLink,
927
+ InMemoryCache
928
+ } from "@apollo/client";
929
+ import { registerApolloClient } from "@apollo/client-integration-nextjs";
930
+ import { cookies as cookies3 } from "next/headers";
931
+ import React from "react";
932
+ import { Suspense } from "react";
933
+ function Injector({
934
+ fetch: fetch2,
935
+ Component,
936
+ props
937
+ }) {
938
+ return /* @__PURE__ */ React.createElement(Suspense, { fallback: /* @__PURE__ */ React.createElement(Component, { ...props || {}, loading: true }) }, /* @__PURE__ */ React.createElement(InjectorSuspensed, { Component, fetch: fetch2, props }));
939
+ }
940
+ async function InjectorSuspensed({
941
+ fetch: fetch2,
942
+ Component,
943
+ props
944
+ }) {
945
+ const data = await fetch2();
946
+ return /* @__PURE__ */ React.createElement(Component, { loading: false, ...props || {}, data });
947
+ }
948
+ var { query: gqlQuery } = registerApolloClient(() => {
949
+ return new ApolloClient({
950
+ cache: new InMemoryCache(),
951
+ link: new HttpLink({
952
+ uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
953
+ })
954
+ });
955
+ });
956
+ var query = async (_query, options) => {
957
+ const res = await gqlQuery({
958
+ query: _query,
959
+ variables: options?.variables,
960
+ context: {
961
+ headers: {
962
+ Cookie: options?.noCookie ? void 0 : await cookies3()
963
+ },
964
+ fetchOptions: {
965
+ cache: options?.revalidate ? "force-cache" : void 0,
966
+ next: {
967
+ revalidate: options?.revalidate || 0,
968
+ tags: options?.tags
969
+ }
970
+ }
971
+ }
972
+ });
973
+ return res.data;
974
+ };
975
+
976
+ // src/graphql/next.tsx
977
+ import { HttpLink as HttpLink2 } from "@apollo/client";
978
+ import {
979
+ ApolloClient as ApolloClient2,
980
+ ApolloNextAppProvider,
981
+ InMemoryCache as InMemoryCache2
982
+ } from "@apollo/client-integration-nextjs";
983
+ import React2 from "react";
984
+ function makeClient(cacheConfig) {
985
+ return new ApolloClient2({
986
+ cache: new InMemoryCache2(cacheConfig),
987
+ link: new HttpLink2({
988
+ uri: getEnv("NEXT_PUBLIC_GRAPHQL_ENDPOINT" /* NEXT_PUBLIC_GRAPHQL_ENDPOINT */)
989
+ })
990
+ });
991
+ }
992
+ var ApolloWrapper = ({
993
+ children,
994
+ cacheConfig
995
+ }) => {
996
+ return /* @__PURE__ */ React2.createElement(ApolloNextAppProvider, { makeClient: () => makeClient(cacheConfig) }, children);
997
+ };
908
998
  export {
999
+ ApolloWrapper,
909
1000
  FieldLibrary,
910
1001
  GQLError,
1002
+ Injector,
911
1003
  QueryLibrary,
912
1004
  field,
913
- initGraphQLServer,
914
- query
1005
+ query,
1006
+ resolver,
1007
+ setupGraphQL
915
1008
  };
@@ -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
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * Use subpath imports for the specific module you need:
5
5
  * - `naystack/auth` — Email/Google/Instagram authentication
6
- * - `naystack/auth/email/client` — Client-side auth hooks (useLogin, useSignUp, etc.)
7
- * - `naystack/graphql` — GraphQL server: query, field, QueryLibrary, FieldLibrary, initGraphQLServer
6
+ * - `naystack/auth/client` — Client-side auth hooks (useLogin, useSignUp, etc.)
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
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * Use subpath imports for the specific module you need:
5
5
  * - `naystack/auth` — Email/Google/Instagram authentication
6
- * - `naystack/auth/email/client` — Client-side auth hooks (useLogin, useSignUp, etc.)
7
- * - `naystack/graphql` — GraphQL server: query, field, QueryLibrary, FieldLibrary, initGraphQLServer
6
+ * - `naystack/auth/client` — Client-side auth hooks (useLogin, useSignUp, etc.)
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
@@ -9,10 +9,10 @@ import { NextRequest } from 'next/server';
9
9
  *
10
10
  * @param options - Configuration object.
11
11
  * @param options.secret - The verify token you configured in the Meta Developer Portal.
12
- * @param options.callback - Called for each webhook event: `(type, value, pageId) => Promise<void>`.
12
+ * @param options.callback - Called for each webhook event: `(type, value, id) => Promise<void>`.
13
13
  * - `type` — Event type (e.g. `"messaging"`, `"changes"`).
14
14
  * - `value` — Event payload.
15
- * - `id` — The page/account id from the entry.
15
+ * - `id` — The entry id (page or account id) from the webhook payload.
16
16
  * @returns Object with `GET` and `POST` — export as your route's handlers.
17
17
  *
18
18
  * @example
@@ -9,10 +9,10 @@ import { NextRequest } from 'next/server';
9
9
  *
10
10
  * @param options - Configuration object.
11
11
  * @param options.secret - The verify token you configured in the Meta Developer Portal.
12
- * @param options.callback - Called for each webhook event: `(type, value, pageId) => Promise<void>`.
12
+ * @param options.callback - Called for each webhook event: `(type, value, id) => Promise<void>`.
13
13
  * - `type` — Event type (e.g. `"messaging"`, `"changes"`).
14
14
  * - `value` — Event payload.
15
- * - `id` — The page/account id from the entry.
15
+ * - `id` — The entry id (page or account id) from the webhook payload.
16
16
  * @returns Object with `GET` and `POST` — export as your route's handlers.
17
17
  *
18
18
  * @example
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/client/hooks.ts
20
+ // src/utils/client/hooks.ts
21
21
  var hooks_exports = {};
22
22
  __export(hooks_exports, {
23
23
  useBreakpoint: () => useBreakpoint,
@@ -1,4 +1,4 @@
1
- // src/client/hooks.ts
1
+ // src/utils/client/hooks.ts
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  function useVisibility(onVisible) {
4
4
  const visibilityRef = useRef(null);
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/client/index.ts
20
+ // src/utils/client/index.ts
21
21
  var client_exports = {};
22
22
  __export(client_exports, {
23
23
  setupSEO: () => setupSEO,
@@ -26,7 +26,7 @@ __export(client_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(client_exports);
28
28
 
29
- // src/client/hooks.ts
29
+ // src/utils/client/hooks.ts
30
30
  var import_react = require("react");
31
31
  function useVisibility(onVisible) {
32
32
  const visibilityRef = (0, import_react.useRef)(null);
@@ -121,7 +121,7 @@ function getEnv(key, skipCheck) {
121
121
  return value;
122
122
  }
123
123
 
124
- // src/client/seo.ts
124
+ // src/utils/client/seo.ts
125
125
  var setupSEO = (SEO) => (title, description, image) => ({
126
126
  title: title ? `${title} \u2022 ${SEO.siteName}` : SEO.title,
127
127
  description: description || SEO.description,
@@ -1,4 +1,4 @@
1
- // src/client/hooks.ts
1
+ // src/utils/client/hooks.ts
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  function useVisibility(onVisible) {
4
4
  const visibilityRef = useRef(null);
@@ -93,7 +93,7 @@ function getEnv(key, skipCheck) {
93
93
  return value;
94
94
  }
95
95
 
96
- // src/client/seo.ts
96
+ // src/utils/client/seo.ts
97
97
  var setupSEO = (SEO) => (title, description, image) => ({
98
98
  title: title ? `${title} \u2022 ${SEO.siteName}` : SEO.title,
99
99
  description: description || SEO.description,