@bhooai/nexus-graphql 2.0.11 → 2.0.12

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/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@bhooai/nexus-graphql",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "types": "./src/index.ts",
10
+ "exports": {
11
+ ".": "./src/index.ts",
12
+ "./builtin/hello": "./src/builtin/helloSubgraph.ts",
13
+ "./builtin": "./src/builtin/index.ts"
14
+ },
10
15
  "scripts": {
11
16
  "build": "tsc -p tsconfig.json",
12
17
  "test": "vitest run"
@@ -0,0 +1,38 @@
1
+ import { defineSubgraph } from '../subgraph/defineSubgraph.js';
2
+ import type { GraphQLContext } from '../types.js';
3
+ import { getCsrfToken, issueCsrfToken } from '@bhooai/nexus-auth';
4
+
5
+ /** Default hello/ping typeDefs included in every project. */
6
+ export const helloTypeDefs = /* GraphQL */ `
7
+ type Query {
8
+ hello: String!
9
+ ping(message: String): String!
10
+ csrfToken: String
11
+ }
12
+ `;
13
+
14
+ export const helloSubgraph = defineSubgraph({
15
+ name: 'hello',
16
+ typeDefs: helloTypeDefs,
17
+ resolvers: {
18
+ Query: {
19
+ hello: () => 'Hello from Nexus!',
20
+ ping: (_parent: unknown, args: { message?: string }) => `pong: ${args.message ?? 'hi'}`,
21
+ csrfToken: (_parent: unknown, _args: unknown, context: GraphQLContext) => {
22
+ const reqCtx = context.request as Parameters<typeof getCsrfToken>[0] | undefined;
23
+ if (!reqCtx) return null;
24
+ // Return the existing cookie token WITHOUT rotating it, so previously
25
+ // issued tokens (e.g. the urlbar's appended csrf) keep matching.
26
+ const existing = getCsrfToken(reqCtx);
27
+ if (existing) return existing;
28
+ try {
29
+ return issueCsrfToken(reqCtx);
30
+ } catch {
31
+ return null;
32
+ }
33
+ },
34
+ },
35
+ },
36
+ });
37
+
38
+ export default helloSubgraph;
@@ -0,0 +1,3 @@
1
+ export * from './helloSubgraph.js';
2
+ export { default as helloSubgraph } from './helloSubgraph.js';
3
+ export { helloTypeDefs } from './helloSubgraph.js';