@cedarjs/graphql-server 9.0.0-canary.1784 → 9.0.0-canary.3124
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/dist/createGraphQLYoga.d.ts +31 -5
- package/dist/createGraphQLYoga.d.ts.map +1 -1
- package/dist/createGraphQLYoga.js +43 -22
- package/dist/directives/makeDirectives.d.ts +2 -2
- package/dist/directives/makeDirectives.d.ts.map +1 -1
- package/dist/errors.d.ts +12 -8
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +10 -8
- package/dist/functions/graphql.d.ts +1 -1
- package/dist/functions/graphql.d.ts.map +1 -1
- package/dist/functions/graphql.js +60 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/makeMergedSchema.d.ts +6 -6
- package/dist/makeMergedSchema.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +8 -8
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +20 -16
- package/dist/plugins/useCedarAuthContext.d.ts +8 -0
- package/dist/plugins/useCedarAuthContext.d.ts.map +1 -0
- package/dist/plugins/{useRedwoodAuthContext.js → useCedarAuthContext.js} +5 -12
- package/dist/{cjs/plugins/useRedwoodError.d.ts → plugins/useCedarError.d.ts} +4 -4
- package/dist/plugins/useCedarError.d.ts.map +1 -0
- package/dist/plugins/{useRedwoodError.js → useCedarError.js} +5 -5
- package/dist/plugins/{useRedwoodGlobalContextSetter.d.ts → useCedarGlobalContextSetter.d.ts} +2 -2
- package/dist/plugins/useCedarGlobalContextSetter.d.ts.map +1 -0
- package/dist/plugins/{useRedwoodGlobalContextSetter.js → useCedarGlobalContextSetter.js} +2 -2
- package/dist/plugins/{useRedwoodLogger.d.ts → useCedarLogger.d.ts} +2 -2
- package/dist/plugins/useCedarLogger.d.ts.map +1 -0
- package/dist/plugins/{useRedwoodLogger.js → useCedarLogger.js} +11 -4
- package/dist/plugins/{useRedwoodOpenTelemetry.d.ts → useCedarOpenTelemetry.d.ts} +3 -3
- package/dist/plugins/useCedarOpenTelemetry.d.ts.map +1 -0
- package/dist/plugins/{useRedwoodOpenTelemetry.js → useCedarOpenTelemetry.js} +3 -3
- package/dist/{cjs/plugins/useRedwoodPopulateContext.d.ts → plugins/useCedarPopulateContext.d.ts} +2 -2
- package/dist/plugins/useCedarPopulateContext.d.ts.map +1 -0
- package/dist/plugins/{useRedwoodPopulateContext.js → useCedarPopulateContext.js} +2 -2
- package/dist/{cjs/plugins/useRedwoodTrustedDocuments.d.ts → plugins/useCedarTrustedDocuments.d.ts} +5 -3
- package/dist/plugins/useCedarTrustedDocuments.d.ts.map +1 -0
- package/dist/plugins/{useRedwoodTrustedDocuments.js → useCedarTrustedDocuments.js} +20 -13
- package/dist/plugins/useRedwoodDirective.d.ts +9 -3
- package/dist/plugins/useRedwoodDirective.d.ts.map +1 -1
- package/dist/plugins/useRedwoodDirective.js +4 -2
- package/dist/serverAuthState.d.ts +25 -0
- package/dist/serverAuthState.d.ts.map +1 -0
- package/dist/serverAuthState.js +10 -0
- package/dist/subscriptions/makeSubscriptions.d.ts +3 -3
- package/dist/subscriptions/makeSubscriptions.d.ts.map +1 -1
- package/dist/types.d.ts +27 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +30 -37
- package/LICENSE +0 -21
- package/dist/cjs/cors.d.ts +0 -10
- package/dist/cjs/cors.d.ts.map +0 -1
- package/dist/cjs/cors.js +0 -70
- package/dist/cjs/createGraphQLYoga.d.ts +0 -6
- package/dist/cjs/createGraphQLYoga.d.ts.map +0 -1
- package/dist/cjs/createGraphQLYoga.js +0 -178
- package/dist/cjs/directives/makeDirectives.d.ts +0 -8
- package/dist/cjs/directives/makeDirectives.d.ts.map +0 -1
- package/dist/cjs/directives/makeDirectives.js +0 -89
- package/dist/cjs/errors.d.ts +0 -28
- package/dist/cjs/errors.d.ts.map +0 -1
- package/dist/cjs/errors.js +0 -98
- package/dist/cjs/functions/graphql.d.ts +0 -15
- package/dist/cjs/functions/graphql.d.ts.map +0 -1
- package/dist/cjs/functions/graphql.js +0 -141
- package/dist/cjs/functions/useRequireAuth.d.ts +0 -12
- package/dist/cjs/functions/useRequireAuth.d.ts.map +0 -1
- package/dist/cjs/functions/useRequireAuth.js +0 -70
- package/dist/cjs/global.api-auto-imports.d.ts +0 -7
- package/dist/cjs/global.api-auto-imports.d.ts.map +0 -1
- package/dist/cjs/global.api-auto-imports.js +0 -1
- package/dist/cjs/globalContext.d.ts +0 -25
- package/dist/cjs/globalContext.d.ts.map +0 -1
- package/dist/cjs/globalContext.js +0 -55
- package/dist/cjs/globalContextStore.d.ts +0 -9
- package/dist/cjs/globalContextStore.d.ts.map +0 -1
- package/dist/cjs/globalContextStore.js +0 -35
- package/dist/cjs/graphiql.d.ts +0 -8
- package/dist/cjs/graphiql.d.ts.map +0 -1
- package/dist/cjs/graphiql.js +0 -45
- package/dist/cjs/index.d.ts +0 -14
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -75
- package/dist/cjs/introspection.d.ts +0 -7
- package/dist/cjs/introspection.d.ts.map +0 -1
- package/dist/cjs/introspection.js +0 -36
- package/dist/cjs/makeMergedSchema.d.ts +0 -17
- package/dist/cjs/makeMergedSchema.d.ts.map +0 -1
- package/dist/cjs/makeMergedSchema.js +0 -283
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/plugins/index.d.ts +0 -10
- package/dist/cjs/plugins/index.d.ts.map +0 -1
- package/dist/cjs/plugins/index.js +0 -52
- package/dist/cjs/plugins/useArmor.d.ts +0 -4
- package/dist/cjs/plugins/useArmor.d.ts.map +0 -1
- package/dist/cjs/plugins/useArmor.js +0 -69
- package/dist/cjs/plugins/useRedwoodAuthContext.d.ts +0 -9
- package/dist/cjs/plugins/useRedwoodAuthContext.d.ts.map +0 -1
- package/dist/cjs/plugins/useRedwoodAuthContext.js +0 -60
- package/dist/cjs/plugins/useRedwoodDirective.d.ts +0 -83
- package/dist/cjs/plugins/useRedwoodDirective.d.ts.map +0 -1
- package/dist/cjs/plugins/useRedwoodDirective.js +0 -166
- package/dist/cjs/plugins/useRedwoodError.d.ts.map +0 -1
- package/dist/cjs/plugins/useRedwoodError.js +0 -62
- package/dist/cjs/plugins/useRedwoodGlobalContextSetter.d.ts +0 -9
- package/dist/cjs/plugins/useRedwoodGlobalContextSetter.d.ts.map +0 -1
- package/dist/cjs/plugins/useRedwoodGlobalContextSetter.js +0 -35
- package/dist/cjs/plugins/useRedwoodLogger.d.ts +0 -115
- package/dist/cjs/plugins/useRedwoodLogger.d.ts.map +0 -1
- package/dist/cjs/plugins/useRedwoodLogger.js +0 -149
- package/dist/cjs/plugins/useRedwoodOpenTelemetry.d.ts +0 -22
- package/dist/cjs/plugins/useRedwoodOpenTelemetry.d.ts.map +0 -1
- package/dist/cjs/plugins/useRedwoodOpenTelemetry.js +0 -156
- package/dist/cjs/plugins/useRedwoodPopulateContext.d.ts.map +0 -1
- package/dist/cjs/plugins/useRedwoodPopulateContext.js +0 -35
- package/dist/cjs/plugins/useRedwoodTrustedDocuments.d.ts.map +0 -1
- package/dist/cjs/plugins/useRedwoodTrustedDocuments.js +0 -80
- package/dist/cjs/rootSchema.d.ts +0 -25
- package/dist/cjs/rootSchema.d.ts.map +0 -1
- package/dist/cjs/rootSchema.js +0 -108
- package/dist/cjs/subscriptions/makeSubscriptions.d.ts +0 -18
- package/dist/cjs/subscriptions/makeSubscriptions.d.ts.map +0 -1
- package/dist/cjs/subscriptions/makeSubscriptions.js +0 -40
- package/dist/cjs/types.d.ts +0 -227
- package/dist/cjs/types.d.ts.map +0 -1
- package/dist/cjs/types.js +0 -16
- package/dist/plugins/useRedwoodAuthContext.d.ts +0 -9
- package/dist/plugins/useRedwoodAuthContext.d.ts.map +0 -1
- package/dist/plugins/useRedwoodError.d.ts +0 -20
- package/dist/plugins/useRedwoodError.d.ts.map +0 -1
- package/dist/plugins/useRedwoodGlobalContextSetter.d.ts.map +0 -1
- package/dist/plugins/useRedwoodLogger.d.ts.map +0 -1
- package/dist/plugins/useRedwoodOpenTelemetry.d.ts.map +0 -1
- package/dist/plugins/useRedwoodPopulateContext.d.ts +0 -9
- package/dist/plugins/useRedwoodPopulateContext.d.ts.map +0 -1
- package/dist/plugins/useRedwoodTrustedDocuments.d.ts +0 -23
- package/dist/plugins/useRedwoodTrustedDocuments.d.ts.map +0 -1
|
@@ -1,6 +1,32 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import type { YogaServerInstance } from 'graphql-yoga';
|
|
3
|
+
import type { Logger } from '@cedarjs/api/logger';
|
|
4
|
+
import type { CedarRequestContext } from '@cedarjs/api/runtime';
|
|
5
|
+
import type { GraphQLYogaOptions, CedarGraphQLContext } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* The server context Yoga is created with. The Fastify entry point adds the
|
|
8
|
+
* request and reply it's handling; every entry point adds `cedarContext`.
|
|
9
|
+
*/
|
|
10
|
+
type CedarYogaServerContext = {
|
|
11
|
+
req: FastifyRequest;
|
|
12
|
+
reply: FastifyReply;
|
|
13
|
+
} & CedarGraphQLContext;
|
|
14
|
+
/**
|
|
15
|
+
* A configured Cedar GraphQL server: the Yoga instance, the logger it logs
|
|
16
|
+
* with, and the builder for the request context `yoga.handle` needs to be
|
|
17
|
+
* given. They belong together: the context the builder produces carries the
|
|
18
|
+
* auth state that this instance's plugins read.
|
|
19
|
+
*/
|
|
20
|
+
export interface CedarGraphQLServer {
|
|
21
|
+
yoga: YogaServerInstance<CedarYogaServerContext, Record<string, never>>;
|
|
22
|
+
logger: Logger;
|
|
23
|
+
/**
|
|
24
|
+
* Builds the `cedarContext` to hand `yoga.handle` for a request, with the
|
|
25
|
+
* auth state this server's `getCurrentUser` needs already resolved. Call
|
|
26
|
+
* it before `yoga.handle`, which reads the request body.
|
|
27
|
+
*/
|
|
28
|
+
buildRequestContext: (request: Request) => Promise<CedarRequestContext>;
|
|
29
|
+
}
|
|
30
|
+
export declare const createGraphQLYoga: ({ healthCheckId, loggerConfig, context, getCurrentUser, onException, generateGraphiQLHeader, extraPlugins, authDecoder, cors, services, sdls, directives, armorConfig, allowedOperations, allowIntrospection, allowGraphiQL, defaultError, graphiQLEndpoint, schemaOptions, realtime, trustedDocuments, openTelemetryOptions, includeScalars, }: GraphQLYogaOptions) => Promise<CedarGraphQLServer>;
|
|
31
|
+
export {};
|
|
6
32
|
//# sourceMappingURL=createGraphQLYoga.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGraphQLYoga.d.ts","sourceRoot":"","sources":["../src/createGraphQLYoga.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createGraphQLYoga.d.ts","sourceRoot":"","sources":["../src/createGraphQLYoga.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAQ3D,OAAO,KAAK,EAAU,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAyB/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAEzE;;;GAGG;AACH,KAAK,sBAAsB,GAAG;IAC5B,GAAG,EAAE,cAAc,CAAA;IACnB,KAAK,EAAE,YAAY,CAAA;CACpB,GAAG,mBAAmB,CAAA;AAEvB;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,kBAAkB,CAAC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;IACvE,MAAM,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,mBAAmB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAA;CACxE;AAED,eAAO,MAAM,iBAAiB,GAAU,iVAwBrC,kBAAkB,KAAG,OAAO,CAAC,kBAAkB,CAgMjD,CAAA"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { useDisableIntrospection } from "@envelop/disable-introspection";
|
|
2
2
|
import { useFilterAllowedOperations } from "@envelop/filter-operation-type";
|
|
3
3
|
import { OperationTypeNode } from "graphql";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
useReadinessCheck,
|
|
6
|
+
createYoga,
|
|
7
|
+
useExecutionCancellation
|
|
8
|
+
} from "graphql-yoga";
|
|
9
|
+
import { buildCedarContext } from "@cedarjs/api/runtime";
|
|
5
10
|
import { mapRwCorsOptionsToYoga } from "./cors.js";
|
|
6
11
|
import { makeDirectivesForPlugin } from "./directives/makeDirectives.js";
|
|
7
12
|
import { configureGraphiQLPlayground } from "./graphiql.js";
|
|
@@ -9,17 +14,18 @@ import { configureGraphQLIntrospection } from "./introspection.js";
|
|
|
9
14
|
import { makeMergedSchema } from "./makeMergedSchema.js";
|
|
10
15
|
import {
|
|
11
16
|
useArmor,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
useCedarAuthContext,
|
|
18
|
+
useCedarDirective,
|
|
19
|
+
useCedarError,
|
|
20
|
+
useCedarGlobalContextSetter,
|
|
21
|
+
useCedarOpenTelemetry,
|
|
22
|
+
useCedarLogger,
|
|
23
|
+
useCedarPopulateContext,
|
|
24
|
+
useCedarTrustedDocuments
|
|
20
25
|
} from "./plugins/index.js";
|
|
26
|
+
import { resolveServerAuthState } from "./serverAuthState.js";
|
|
21
27
|
import { makeSubscriptions } from "./subscriptions/makeSubscriptions.js";
|
|
22
|
-
const createGraphQLYoga = ({
|
|
28
|
+
const createGraphQLYoga = async ({
|
|
23
29
|
healthCheckId = "yoga",
|
|
24
30
|
loggerConfig,
|
|
25
31
|
context,
|
|
@@ -45,15 +51,15 @@ const createGraphQLYoga = ({
|
|
|
45
51
|
includeScalars
|
|
46
52
|
}) => {
|
|
47
53
|
let schema;
|
|
48
|
-
let
|
|
54
|
+
let cedarDirectivePlugins = [];
|
|
49
55
|
const logger = loggerConfig.logger;
|
|
50
56
|
const isDevEnv = process.env.NODE_ENV === "development";
|
|
51
57
|
try {
|
|
52
58
|
const projectDirectives = makeDirectivesForPlugin(directives);
|
|
53
59
|
if (projectDirectives.length > 0) {
|
|
54
60
|
;
|
|
55
|
-
|
|
56
|
-
(directive) =>
|
|
61
|
+
cedarDirectivePlugins = projectDirectives.map(
|
|
62
|
+
(directive) => useCedarDirective(directive)
|
|
57
63
|
);
|
|
58
64
|
}
|
|
59
65
|
let projectSubscriptions = [];
|
|
@@ -79,20 +85,25 @@ const createGraphQLYoga = ({
|
|
|
79
85
|
}
|
|
80
86
|
try {
|
|
81
87
|
const plugins = [];
|
|
88
|
+
if (realtime) {
|
|
89
|
+
const { useCedarRealtime } = await import("@cedarjs/realtime");
|
|
90
|
+
plugins.push(useCedarRealtime(realtime));
|
|
91
|
+
}
|
|
92
|
+
plugins.push(useExecutionCancellation());
|
|
82
93
|
const { disableIntrospection } = configureGraphQLIntrospection({
|
|
83
94
|
allowIntrospection
|
|
84
95
|
});
|
|
85
96
|
if (disableIntrospection) {
|
|
86
97
|
plugins.push(useDisableIntrospection());
|
|
87
98
|
}
|
|
88
|
-
plugins.push(
|
|
89
|
-
plugins.push(
|
|
99
|
+
plugins.push(useCedarAuthContext(getCurrentUser));
|
|
100
|
+
plugins.push(useCedarGlobalContextSetter());
|
|
90
101
|
if (context) {
|
|
91
|
-
plugins.push(
|
|
102
|
+
plugins.push(useCedarPopulateContext(context));
|
|
92
103
|
}
|
|
93
|
-
plugins.push(...
|
|
104
|
+
plugins.push(...cedarDirectivePlugins);
|
|
94
105
|
if (openTelemetryOptions !== void 0) {
|
|
95
|
-
plugins.push(
|
|
106
|
+
plugins.push(useCedarOpenTelemetry(openTelemetryOptions));
|
|
96
107
|
}
|
|
97
108
|
plugins.push(useArmor(logger, armorConfig));
|
|
98
109
|
const defaultAllowedOperations = [
|
|
@@ -106,12 +117,12 @@ const createGraphQLYoga = ({
|
|
|
106
117
|
useFilterAllowedOperations(allowedOperations || defaultAllowedOperations)
|
|
107
118
|
);
|
|
108
119
|
if (trustedDocuments && !trustedDocuments.disabled) {
|
|
109
|
-
plugins.push(
|
|
120
|
+
plugins.push(useCedarTrustedDocuments(trustedDocuments));
|
|
110
121
|
}
|
|
111
122
|
if (extraPlugins && extraPlugins.length > 0) {
|
|
112
123
|
plugins.push(...extraPlugins);
|
|
113
124
|
}
|
|
114
|
-
plugins.push(
|
|
125
|
+
plugins.push(useCedarError(logger));
|
|
115
126
|
plugins.push(
|
|
116
127
|
useReadinessCheck({
|
|
117
128
|
endpoint: graphiQLEndpoint + "/readiness",
|
|
@@ -129,7 +140,7 @@ const createGraphQLYoga = ({
|
|
|
129
140
|
}
|
|
130
141
|
})
|
|
131
142
|
);
|
|
132
|
-
plugins.push(
|
|
143
|
+
plugins.push(useCedarLogger(loggerConfig));
|
|
133
144
|
const yoga = createYoga({
|
|
134
145
|
id: healthCheckId,
|
|
135
146
|
landingPage: isDevEnv,
|
|
@@ -151,7 +162,17 @@ const createGraphQLYoga = ({
|
|
|
151
162
|
return mapRwCorsOptionsToYoga(cors, requestOrigin);
|
|
152
163
|
}
|
|
153
164
|
});
|
|
154
|
-
|
|
165
|
+
const buildRequestContext = async (request) => {
|
|
166
|
+
const cedarContext = await buildCedarContext(request);
|
|
167
|
+
return {
|
|
168
|
+
...cedarContext,
|
|
169
|
+
serverAuthState: await resolveServerAuthState(
|
|
170
|
+
{ authDecoder, getCurrentUser },
|
|
171
|
+
request
|
|
172
|
+
)
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
return { yoga, logger, buildRequestContext };
|
|
155
176
|
} catch (e) {
|
|
156
177
|
if (onException) {
|
|
157
178
|
onException();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type DocumentNode } from 'graphql';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CedarDirective, TransformerDirective, TransformerDirectiveFunc, ValidatorDirective, ValidatorDirectiveFunc } from '../plugins/useRedwoodDirective.js';
|
|
3
3
|
export type DirectiveGlobImports = Record<string, any>;
|
|
4
|
-
export declare const makeDirectivesForPlugin: (directiveGlobs: DirectiveGlobImports) =>
|
|
4
|
+
export declare const makeDirectivesForPlugin: (directiveGlobs: DirectiveGlobImports) => CedarDirective[];
|
|
5
5
|
export declare const getDirectiveName: (schema: DocumentNode) => string | undefined;
|
|
6
6
|
export declare const createValidatorDirective: (schema: DocumentNode, directiveFunc: ValidatorDirectiveFunc) => ValidatorDirective;
|
|
7
7
|
export declare const createTransformerDirective: (schema: DocumentNode, directiveFunc: TransformerDirectiveFunc) => TransformerDirective;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeDirectives.d.ts","sourceRoot":"","sources":["../../src/directives/makeDirectives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAEjD,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"makeDirectives.d.ts","sourceRoot":"","sources":["../../src/directives/makeDirectives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAEjD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,mCAAmC,CAAA;AAW1C,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAEtD,eAAO,MAAM,uBAAuB,GAClC,gBAAgB,oBAAoB,KACnC,cAAc,EAwBhB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,QAAQ,YAAY,uBAMpD,CAAA;AAED,eAAO,MAAM,wBAAwB,GACnC,QAAQ,YAAY,EACpB,eAAe,sBAAsB,KACpC,kBAmBF,CAAA;AAED,eAAO,MAAM,0BAA0B,GACrC,QAAQ,YAAY,EACpB,eAAe,wBAAwB,KACtC,oBAmBF,CAAA"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import { GraphQLError } from 'graphql';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class CedarGraphQLError extends GraphQLError {
|
|
3
3
|
constructor(message: string, extensions?: Record<string, any>, originalError?: Error & {
|
|
4
4
|
readonly extensions?: unknown;
|
|
5
5
|
});
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
/** @deprecated Use `CedarGraphQLError` instead */
|
|
8
|
+
export declare const RedwoodGraphQLError: typeof CedarGraphQLError;
|
|
9
|
+
/** @deprecated Use `CedarGraphQLError` instead */
|
|
10
|
+
export type RedwoodGraphQLError = CedarGraphQLError;
|
|
11
|
+
export declare class SyntaxError extends CedarGraphQLError {
|
|
8
12
|
constructor(message: string);
|
|
9
13
|
}
|
|
10
|
-
export declare class ValidationError extends
|
|
14
|
+
export declare class ValidationError extends CedarGraphQLError {
|
|
11
15
|
constructor(message: string);
|
|
12
16
|
}
|
|
13
|
-
export declare class AuthenticationError extends
|
|
17
|
+
export declare class AuthenticationError extends CedarGraphQLError {
|
|
14
18
|
constructor(message: string);
|
|
15
19
|
}
|
|
16
|
-
export declare class ForbiddenError extends
|
|
20
|
+
export declare class ForbiddenError extends CedarGraphQLError {
|
|
17
21
|
constructor(message: string);
|
|
18
22
|
}
|
|
19
|
-
export declare class PersistedQueryNotFoundError extends
|
|
23
|
+
export declare class PersistedQueryNotFoundError extends CedarGraphQLError {
|
|
20
24
|
constructor();
|
|
21
25
|
}
|
|
22
|
-
export declare class PersistedQueryNotSupportedError extends
|
|
26
|
+
export declare class PersistedQueryNotSupportedError extends CedarGraphQLError {
|
|
23
27
|
constructor();
|
|
24
28
|
}
|
|
25
|
-
export declare class UserInputError extends
|
|
29
|
+
export declare class UserInputError extends CedarGraphQLError {
|
|
26
30
|
constructor(message: string, properties?: Record<string, any>);
|
|
27
31
|
}
|
|
28
32
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,qBAAa,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtC,qBAAa,iBAAkB,SAAQ,YAAY;gBAE/C,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,aAAa,CAAC,EAAE,KAAK,GAAG;QACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAC9B;CAYJ;AAED,kDAAkD;AAClD,eAAO,MAAM,mBAAmB,0BAAoB,CAAA;AASpD,kDAAkD;AAClD,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,CAAA;AAEnD,qBAAa,WAAY,SAAQ,iBAAiB;gBACpC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,eAAgB,SAAQ,iBAAiB;gBACxC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,mBAAoB,SAAQ,iBAAiB;gBAC5C,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,cAAe,SAAQ,iBAAiB;gBACvC,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,2BAA4B,SAAQ,iBAAiB;;CAMjE;AAED,qBAAa,+BAAgC,SAAQ,iBAAiB;;CAQrE;AAED,qBAAa,cAAe,SAAQ,iBAAiB;gBACvC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAK9D"}
|
package/dist/errors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLError } from "graphql";
|
|
2
|
-
class
|
|
2
|
+
class CedarGraphQLError extends GraphQLError {
|
|
3
3
|
constructor(message, extensions, originalError) {
|
|
4
4
|
super(message, {
|
|
5
5
|
extensions: {
|
|
@@ -11,37 +11,38 @@ class RedwoodGraphQLError extends GraphQLError {
|
|
|
11
11
|
Object.setPrototypeOf(this, GraphQLError.prototype);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
const RedwoodGraphQLError = CedarGraphQLError;
|
|
15
|
+
class SyntaxError extends CedarGraphQLError {
|
|
15
16
|
constructor(message) {
|
|
16
17
|
super(message, { code: "GRAPHQL_PARSE_FAILED" });
|
|
17
18
|
Object.setPrototypeOf(this, SyntaxError.prototype);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
class ValidationError extends
|
|
21
|
+
class ValidationError extends CedarGraphQLError {
|
|
21
22
|
constructor(message) {
|
|
22
23
|
super(message, { code: "GRAPHQL_VALIDATION_FAILED" });
|
|
23
24
|
Object.setPrototypeOf(this, ValidationError.prototype);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
class AuthenticationError extends
|
|
27
|
+
class AuthenticationError extends CedarGraphQLError {
|
|
27
28
|
constructor(message) {
|
|
28
29
|
super(message, { code: "UNAUTHENTICATED" });
|
|
29
30
|
Object.setPrototypeOf(this, AuthenticationError.prototype);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
class ForbiddenError extends
|
|
33
|
+
class ForbiddenError extends CedarGraphQLError {
|
|
33
34
|
constructor(message) {
|
|
34
35
|
super(message, { code: "FORBIDDEN" });
|
|
35
36
|
Object.setPrototypeOf(this, ForbiddenError.prototype);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
class PersistedQueryNotFoundError extends
|
|
39
|
+
class PersistedQueryNotFoundError extends CedarGraphQLError {
|
|
39
40
|
constructor() {
|
|
40
41
|
super("PersistedQueryNotFound", { code: "PERSISTED_QUERY_NOT_FOUND" });
|
|
41
42
|
Object.setPrototypeOf(this, PersistedQueryNotFoundError.prototype);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
class PersistedQueryNotSupportedError extends
|
|
45
|
+
class PersistedQueryNotSupportedError extends CedarGraphQLError {
|
|
45
46
|
constructor() {
|
|
46
47
|
super("PersistedQueryNotSupported", {
|
|
47
48
|
code: "PERSISTED_QUERY_NOT_SUPPORTED"
|
|
@@ -49,7 +50,7 @@ class PersistedQueryNotSupportedError extends RedwoodGraphQLError {
|
|
|
49
50
|
Object.setPrototypeOf(this, PersistedQueryNotSupportedError.prototype);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
class UserInputError extends
|
|
53
|
+
class UserInputError extends CedarGraphQLError {
|
|
53
54
|
constructor(message, properties) {
|
|
54
55
|
super(message, { code: "BAD_USER_INPUT", properties });
|
|
55
56
|
Object.setPrototypeOf(this, UserInputError.prototype);
|
|
@@ -57,6 +58,7 @@ class UserInputError extends RedwoodGraphQLError {
|
|
|
57
58
|
}
|
|
58
59
|
export {
|
|
59
60
|
AuthenticationError,
|
|
61
|
+
CedarGraphQLError,
|
|
60
62
|
ForbiddenError,
|
|
61
63
|
PersistedQueryNotFoundError,
|
|
62
64
|
PersistedQueryNotSupportedError,
|
|
@@ -11,5 +11,5 @@ import type { GraphQLHandlerOptions } from '../types.js';
|
|
|
11
11
|
* export const handler = createGraphQLHandler({ schema, context, getCurrentUser })
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
export declare const createGraphQLHandler: ({ healthCheckId, loggerConfig, context, getCurrentUser, onException, generateGraphiQLHeader, extraPlugins, authDecoder, cors, services, sdls, directives, armorConfig, allowedOperations, allowIntrospection, allowGraphiQL, defaultError, graphiQLEndpoint, schemaOptions, openTelemetryOptions, trustedDocuments, }: GraphQLHandlerOptions) => (event: APIGatewayProxyEvent, context: LambdaContext) => Promise<any>;
|
|
14
|
+
export declare const createGraphQLHandler: ({ healthCheckId, loggerConfig, context, getCurrentUser, onException, generateGraphiQLHeader, extraPlugins, authDecoder, cors, services, sdls, directives, armorConfig, allowedOperations, allowIntrospection, allowGraphiQL, defaultError, graphiQLEndpoint, schemaOptions, realtime, openTelemetryOptions, trustedDocuments, }: GraphQLHandlerOptions) => (event: APIGatewayProxyEvent, context: LambdaContext) => Promise<any>;
|
|
15
15
|
//# sourceMappingURL=graphql.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/functions/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,IAAI,aAAa,EACzB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/functions/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAEpB,OAAO,IAAI,aAAa,EACzB,MAAM,YAAY,CAAA;AAQnB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AA4CxD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAAI,iUAuBlC,qBAAqB,MA+IpB,OAAO,oBAAoB,EAC3B,SAAS,aAAa,KACrB,OAAO,CAAC,GAAG,CAcf,CAAA"}
|
|
@@ -1,5 +1,35 @@
|
|
|
1
|
+
import * as cookie from "cookie";
|
|
1
2
|
import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
|
|
2
3
|
import { createGraphQLYoga } from "../createGraphQLYoga.js";
|
|
4
|
+
import { resolveServerAuthState } from "../serverAuthState.js";
|
|
5
|
+
function lambdaQueryToSearchParams(event) {
|
|
6
|
+
const query = new URLSearchParams();
|
|
7
|
+
if (event.multiValueQueryStringParameters) {
|
|
8
|
+
for (const [key, values] of Object.entries(
|
|
9
|
+
event.multiValueQueryStringParameters
|
|
10
|
+
)) {
|
|
11
|
+
if (values) {
|
|
12
|
+
for (const value of values) {
|
|
13
|
+
query.append(key, value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
} else if (event.queryStringParameters) {
|
|
18
|
+
for (const [key, value] of Object.entries(event.queryStringParameters)) {
|
|
19
|
+
if (value != null) {
|
|
20
|
+
query.set(key, value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return query;
|
|
25
|
+
}
|
|
26
|
+
function parseLambdaCookies(event) {
|
|
27
|
+
return new Map(
|
|
28
|
+
Object.entries(cookie.parse(event.headers?.cookie ?? "")).filter(
|
|
29
|
+
(entry) => entry[1] !== void 0
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
3
33
|
const createGraphQLHandler = ({
|
|
4
34
|
healthCheckId,
|
|
5
35
|
loggerConfig,
|
|
@@ -20,10 +50,11 @@ const createGraphQLHandler = ({
|
|
|
20
50
|
defaultError = "Something went wrong.",
|
|
21
51
|
graphiQLEndpoint = "/graphql",
|
|
22
52
|
schemaOptions,
|
|
53
|
+
realtime,
|
|
23
54
|
openTelemetryOptions,
|
|
24
55
|
trustedDocuments
|
|
25
56
|
}) => {
|
|
26
|
-
const
|
|
57
|
+
const yogaAndLoggerPromise = createGraphQLYoga({
|
|
27
58
|
healthCheckId,
|
|
28
59
|
loggerConfig,
|
|
29
60
|
context,
|
|
@@ -43,11 +74,13 @@ const createGraphQLHandler = ({
|
|
|
43
74
|
defaultError,
|
|
44
75
|
graphiQLEndpoint,
|
|
45
76
|
schemaOptions,
|
|
77
|
+
realtime,
|
|
46
78
|
openTelemetryOptions,
|
|
47
79
|
trustedDocuments
|
|
48
80
|
});
|
|
49
81
|
const handlerFn = async (event, requestContext) => {
|
|
50
82
|
requestContext.callbackWaitsForEmptyEventLoop = false;
|
|
83
|
+
const { yoga, logger } = await yogaAndLoggerPromise;
|
|
51
84
|
let lambdaResponse;
|
|
52
85
|
try {
|
|
53
86
|
const [, rest = ""] = event.path.split(graphiQLEndpoint);
|
|
@@ -69,7 +102,17 @@ const createGraphQLHandler = ({
|
|
|
69
102
|
},
|
|
70
103
|
{
|
|
71
104
|
event,
|
|
72
|
-
requestContext
|
|
105
|
+
requestContext,
|
|
106
|
+
cedarContext: {
|
|
107
|
+
params: event.pathParameters ?? {},
|
|
108
|
+
query: lambdaQueryToSearchParams(event),
|
|
109
|
+
cookies: parseLambdaCookies(event),
|
|
110
|
+
serverAuthState: await resolveServerAuthState(
|
|
111
|
+
{ authDecoder, getCurrentUser },
|
|
112
|
+
event,
|
|
113
|
+
requestContext
|
|
114
|
+
)
|
|
115
|
+
}
|
|
73
116
|
}
|
|
74
117
|
);
|
|
75
118
|
const responseHeaders = {};
|
|
@@ -83,15 +126,22 @@ const createGraphQLHandler = ({
|
|
|
83
126
|
isBase64Encoded: false
|
|
84
127
|
};
|
|
85
128
|
} catch (e) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
129
|
+
if (!!e && typeof e === "object" && "code" in e && e.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
130
|
+
lambdaResponse = {
|
|
131
|
+
body: JSON.stringify({ error: "Client disconnected" }),
|
|
132
|
+
statusCode: 499
|
|
133
|
+
};
|
|
134
|
+
} else {
|
|
135
|
+
logger.error(e);
|
|
136
|
+
if (onException) {
|
|
137
|
+
onException();
|
|
138
|
+
}
|
|
139
|
+
lambdaResponse = {
|
|
140
|
+
body: JSON.stringify({ error: "GraphQL execution failed" }),
|
|
141
|
+
statusCode: 200
|
|
142
|
+
// should be 500
|
|
143
|
+
};
|
|
89
144
|
}
|
|
90
|
-
lambdaResponse = {
|
|
91
|
-
body: JSON.stringify({ error: "GraphQL execution failed" }),
|
|
92
|
-
statusCode: 200
|
|
93
|
-
// should be 500
|
|
94
|
-
};
|
|
95
145
|
}
|
|
96
146
|
if (!lambdaResponse.headers) {
|
|
97
147
|
lambdaResponse.headers = {};
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export * from './makeMergedSchema.js';
|
|
|
7
7
|
export * from './createGraphQLYoga.js';
|
|
8
8
|
export * from './types.js';
|
|
9
9
|
export { createValidatorDirective, createTransformerDirective, getDirectiveName, makeDirectivesForPlugin, } from './directives/makeDirectives.js';
|
|
10
|
-
export { hasDirective, DirectiveType, useRedwoodDirective, } from './plugins/useRedwoodDirective.js';
|
|
11
|
-
export type { DirectiveParams, RedwoodDirective, ValidatorDirective, ValidatorDirectiveFunc, TransformerDirective, TransformerDirectiveFunc, ValidateArgs, TransformArgs, } from './plugins/useRedwoodDirective.js';
|
|
10
|
+
export { hasDirective, DirectiveType, useCedarDirective, useRedwoodDirective, } from './plugins/useRedwoodDirective.js';
|
|
11
|
+
export type { DirectiveParams, CedarDirective, RedwoodDirective, ValidatorDirective, ValidatorDirectiveFunc, TransformerDirective, TransformerDirectiveFunc, ValidateArgs, TransformArgs, } from './plugins/useRedwoodDirective.js';
|
|
12
12
|
export * as rootSchema from './rootSchema.js';
|
|
13
13
|
export { context, setContext } from '@cedarjs/context';
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,cAAc,8BAA8B,CAAA;AAE5C,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,YAAY,CAAA;AAE1B,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EACL,YAAY,EACZ,aAAa,EACb,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AAEzC,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,YAAY,EACZ,aAAa,GACd,MAAM,kCAAkC,CAAA;AAEzC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAG7C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAA;AAErC,cAAc,8BAA8B,CAAA;AAE5C,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,YAAY,CAAA;AAE1B,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EACL,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AAEzC,YAAY,EACV,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,YAAY,EACZ,aAAa,GACd,MAAM,kCAAkC,CAAA;AAEzC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAG7C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
hasDirective,
|
|
17
17
|
DirectiveType,
|
|
18
|
+
useCedarDirective,
|
|
18
19
|
useRedwoodDirective
|
|
19
20
|
} from "./plugins/useRedwoodDirective.js";
|
|
20
21
|
import * as rootSchema from "./rootSchema.js";
|
|
@@ -29,5 +30,6 @@ export {
|
|
|
29
30
|
makeDirectivesForPlugin,
|
|
30
31
|
rootSchema,
|
|
31
32
|
setContext,
|
|
33
|
+
useCedarDirective,
|
|
32
34
|
useRedwoodDirective
|
|
33
35
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { IExecutableSchemaDefinition } from '@graphql-tools/schema';
|
|
2
2
|
import type { GraphQLSchema } from 'graphql';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { ServicesGlobImports, SdlGlobImports,
|
|
3
|
+
import type { CedarDirective } from './plugins/useRedwoodDirective.js';
|
|
4
|
+
import type { CedarSubscription } from './subscriptions/makeSubscriptions.js';
|
|
5
|
+
import type { ServicesGlobImports, SdlGlobImports, CedarScalarConfig } from './types.js';
|
|
6
6
|
export declare const makeMergedSchema: ({ sdls, services, schemaOptions, directives, subscriptions, includeScalars, }: {
|
|
7
7
|
sdls: SdlGlobImports;
|
|
8
8
|
services: ServicesGlobImports;
|
|
9
|
-
directives:
|
|
10
|
-
subscriptions:
|
|
11
|
-
includeScalars?:
|
|
9
|
+
directives: CedarDirective[];
|
|
10
|
+
subscriptions: CedarSubscription[];
|
|
11
|
+
includeScalars?: CedarScalarConfig;
|
|
12
12
|
/**
|
|
13
13
|
* A list of options passed to [makeExecutableSchema](https://www.graphql-tools.com/docs/generate-schema/#makeexecutableschemaoptions).
|
|
14
14
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeMergedSchema.d.ts","sourceRoot":"","sources":["../src/makeMergedSchema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAUxE,OAAO,KAAK,EACV,aAAa,EAKd,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"makeMergedSchema.d.ts","sourceRoot":"","sources":["../src/makeMergedSchema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAUxE,OAAO,KAAK,EACV,aAAa,EAKd,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAA;AAEtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAC7E,OAAO,KAAK,EAEV,mBAAmB,EAEnB,cAAc,EACd,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAuUnB,eAAO,MAAM,gBAAgB,GAAI,+EAO9B;IACD,IAAI,EAAE,cAAc,CAAA;IACpB,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,UAAU,EAAE,cAAc,EAAE,CAAA;IAC5B,aAAa,EAAE,iBAAiB,EAAE,CAAA;IAClC,cAAc,CAAC,EAAE,iBAAiB,CAAA;IAElC;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAA;CACrD,kBA+CA,CAAA"}
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { useArmor } from './useArmor.js';
|
|
2
|
-
export {
|
|
3
|
-
export { useRedwoodDirective } from './useRedwoodDirective.js';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
2
|
+
export { useCedarAuthContext } from './useCedarAuthContext.js';
|
|
3
|
+
export { useCedarDirective, useRedwoodDirective, } from './useRedwoodDirective.js';
|
|
4
|
+
export { useCedarError } from './useCedarError.js';
|
|
5
|
+
export { useCedarGlobalContextSetter } from './useCedarGlobalContextSetter.js';
|
|
6
|
+
export { useCedarLogger } from './useCedarLogger.js';
|
|
7
|
+
export { useCedarTrustedDocuments } from './useCedarTrustedDocuments.js';
|
|
8
|
+
export { useCedarPopulateContext } from './useCedarPopulateContext.js';
|
|
9
|
+
export { useCedarOpenTelemetry } from './useCedarOpenTelemetry.js';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EACL,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAA;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AAExE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA"}
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { useArmor } from "./useArmor.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
2
|
+
import { useCedarAuthContext } from "./useCedarAuthContext.js";
|
|
3
|
+
import {
|
|
4
|
+
useCedarDirective,
|
|
5
|
+
useRedwoodDirective
|
|
6
|
+
} from "./useRedwoodDirective.js";
|
|
7
|
+
import { useCedarError } from "./useCedarError.js";
|
|
8
|
+
import { useCedarGlobalContextSetter } from "./useCedarGlobalContextSetter.js";
|
|
9
|
+
import { useCedarLogger } from "./useCedarLogger.js";
|
|
10
|
+
import { useCedarTrustedDocuments } from "./useCedarTrustedDocuments.js";
|
|
11
|
+
import { useCedarPopulateContext } from "./useCedarPopulateContext.js";
|
|
12
|
+
import { useCedarOpenTelemetry } from "./useCedarOpenTelemetry.js";
|
|
10
13
|
export {
|
|
11
14
|
useArmor,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
useCedarAuthContext,
|
|
16
|
+
useCedarDirective,
|
|
17
|
+
useCedarError,
|
|
18
|
+
useCedarGlobalContextSetter,
|
|
19
|
+
useCedarLogger,
|
|
20
|
+
useCedarOpenTelemetry,
|
|
21
|
+
useCedarPopulateContext,
|
|
22
|
+
useCedarTrustedDocuments,
|
|
23
|
+
useRedwoodDirective
|
|
20
24
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Plugin } from 'graphql-yoga';
|
|
2
|
+
import type { CedarGraphQLContext, GraphQLHandlerOptions } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Envelop plugin for injecting the current user into the GraphQL Context,
|
|
5
|
+
* based on custom getCurrentUser function.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useCedarAuthContext: (getCurrentUser: GraphQLHandlerOptions["getCurrentUser"]) => Plugin<CedarGraphQLContext>;
|
|
8
|
+
//# sourceMappingURL=useCedarAuthContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCedarAuthContext.d.ts","sourceRoot":"","sources":["../../src/plugins/useCedarAuthContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAI1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,gBAAgB,qBAAqB,CAAC,gBAAgB,CAAC,KACtD,MAAM,CAAC,mBAAmB,CA4C5B,CAAA"}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
const useRedwoodAuthContext = (getCurrentUser, authDecoder) => {
|
|
1
|
+
const useCedarAuthContext = (getCurrentUser) => {
|
|
3
2
|
return {
|
|
4
3
|
async onContextBuilding({ context, extendContext }) {
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
authContext = await getAuthenticationContext({
|
|
8
|
-
authDecoder,
|
|
9
|
-
event: context.event,
|
|
10
|
-
context: context.requestContext
|
|
11
|
-
});
|
|
12
|
-
} catch (error) {
|
|
4
|
+
if (!context.cedarContext && getCurrentUser) {
|
|
13
5
|
throw new Error(
|
|
14
|
-
`
|
|
6
|
+
"Auth state is resolved when a request enters Cedar and passed on the GraphQL context, but this context has no `cedarContext`. Whatever is invoking `yoga.handle` needs to build one with the `buildRequestContext` returned by `createGraphQLYoga` and pass it as `cedarContext`."
|
|
15
7
|
);
|
|
16
8
|
}
|
|
9
|
+
const authContext = context.cedarContext?.serverAuthState;
|
|
17
10
|
try {
|
|
18
11
|
if (authContext) {
|
|
19
12
|
const currentUser = getCurrentUser ? await getCurrentUser(
|
|
@@ -32,5 +25,5 @@ const useRedwoodAuthContext = (getCurrentUser, authDecoder) => {
|
|
|
32
25
|
};
|
|
33
26
|
};
|
|
34
27
|
export {
|
|
35
|
-
|
|
28
|
+
useCedarAuthContext
|
|
36
29
|
};
|