@nwire/apollo 0.10.1 → 0.11.0

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.
@@ -44,7 +44,7 @@
44
44
  * one-liner that says "this GraphQL field is implemented by this Nwire
45
45
  * action" — same migration story Express got.
46
46
  */
47
- import type { ActionDefinition, ForgeApp } from "@nwire/forge";
47
+ import type { ActionDefinition, ForgeDispatcher } from "@nwire/forge";
48
48
  import { type MessageEnvelope } from "@nwire/envelope";
49
49
  import type { ApolloServerOptions, BaseContext } from "@apollo/server";
50
50
  import type { GraphQLFormattedError } from "graphql";
@@ -55,7 +55,7 @@ import type { GraphQLFormattedError } from "graphql";
55
55
  */
56
56
  export interface NwireApolloContext extends BaseContext {
57
57
  /** The Nwire app to dispatch actions through. */
58
- readonly app: ForgeApp;
58
+ readonly dispatcher: ForgeDispatcher;
59
59
  /**
60
60
  * The fresh envelope seeded for this GraphQL request. Resolvers can
61
61
  * dispatch through `runtime` and the envelope will be derived as a
@@ -87,11 +87,11 @@ export interface ActionResolverOptions<TContext extends BaseContext = NwireApoll
87
87
  readonly extractInput?: (args: Record<string, unknown>, context: TContext) => unknown;
88
88
  readonly extractEnvelope?: (context: TContext) => MessageEnvelope;
89
89
  /**
90
- * How to find the app. Defaults to `context.app`. Provide this if
91
- * your context shape names the app differently or pulls it from a
92
- * DI container.
90
+ * How to find the dispatcher. Defaults to `context.dispatcher`. Provide
91
+ * this if your context names it differently or pulls it from a DI
92
+ * container.
93
93
  */
94
- readonly resolveApp?: (context: TContext) => ForgeApp;
94
+ readonly resolveDispatcher?: (context: TContext) => ForgeDispatcher;
95
95
  }
96
96
  /**
97
97
  * Wrap a Nwire `ActionDefinition` as a GraphQL field resolver.
@@ -141,7 +141,7 @@ export declare function actionResolver<TContext extends NwireApolloContext = Nwi
141
141
  * type usable in any integration without a forced cast.
142
142
  */
143
143
  export interface NwireApolloContextOptions<TArgs = unknown> {
144
- readonly app: ForgeApp;
144
+ readonly dispatcher: ForgeDispatcher;
145
145
  /**
146
146
  * Build a request-scoped envelope. The integration arg (`req`, headers,
147
147
  * etc.) is available so caller can read auth headers. Defaults to a
@@ -176,7 +176,7 @@ export declare function nwireApolloContext<TArgs = unknown>(options: NwireApollo
176
176
  * `startStandaloneServer` / `expressMiddleware` as appropriate.
177
177
  */
178
178
  export interface MountNwireOptions<TArgs = unknown> {
179
- readonly app: ForgeApp;
179
+ readonly dispatcher: ForgeDispatcher;
180
180
  readonly extractEnvelope?: (args: TArgs) => MessageEnvelope;
181
181
  readonly extractUser?: (args: TArgs) => unknown;
182
182
  }
@@ -77,34 +77,34 @@ export function actionResolver(action, options = {}) {
77
77
  // to the whole args object so query-style resolvers (where each arg
78
78
  // is named separately) work without configuration.
79
79
  "input" in args ? args.input : args);
80
- const resolveApp = options.resolveApp ?? ((ctx) => ctx.app);
80
+ const resolveDispatcher = options.resolveDispatcher ?? ((ctx) => ctx.dispatcher);
81
81
  const extractEnvelope = options.extractEnvelope ??
82
82
  ((ctx) =>
83
83
  // If `nwireApolloContext` is used the envelope is already on the
84
84
  // context; otherwise fall back to seeding one from the loose user
85
- // field. Either way `runtime.dispatch` derives a child envelope for
86
- // the actual action, so this just sets the root of the chain.
85
+ // field. Either way the dispatcher derives a child envelope for the
86
+ // actual action, so this just sets the root of the chain.
87
87
  ctx.envelope ?? seedEnvelope({ user: ctx.user }));
88
88
  return async (_parent, args, context) => {
89
- const app = resolveApp(context);
89
+ const dispatcher = resolveDispatcher(context);
90
90
  const envelope = extractEnvelope(context);
91
91
  const input = extractInput(args, context);
92
- return app.dispatch(action, input, envelope);
92
+ return dispatcher.dispatch(action, input, envelope);
93
93
  };
94
94
  }
95
95
  export function nwireApolloContext(options) {
96
- const { app, extractEnvelope, extractUser } = options;
96
+ const { dispatcher, extractEnvelope, extractUser } = options;
97
97
  return async (args) => {
98
98
  const user = extractUser?.(args);
99
99
  const envelope = extractEnvelope?.(args) ?? seedEnvelope(user !== undefined ? { user } : {});
100
- return { app, envelope, user };
100
+ return { dispatcher, envelope, user };
101
101
  };
102
102
  }
103
103
  export function mountNwireOnApollo(options) {
104
104
  return {
105
105
  formatError: formatNwireError,
106
106
  context: nwireApolloContext({
107
- app: options.app,
107
+ dispatcher: options.dispatcher,
108
108
  extractEnvelope: options.extractEnvelope,
109
109
  extractUser: options.extractUser,
110
110
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nwire/apollo",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Nwire — Apollo Server (v4) interop adapter. actionResolver(action) plugs a Nwire ActionDefinition into a GraphQL schema as a field resolver; nwireApolloContext({ runtime }) adds runtime.dispatch + envelope to Apollo's per-request context; mountNwireOnApollo() registers Nwire-aware error mapping (defineError -> extensions.code). Opt-in, peer dep, ~60 LOC of real code.",
5
5
  "keywords": [
6
6
  "adapter",
@@ -28,8 +28,8 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@nwire/envelope": "0.10.1",
32
- "@nwire/forge": "0.10.1"
31
+ "@nwire/forge": "0.11.0",
32
+ "@nwire/envelope": "0.11.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@apollo/server": "^4.11.0",