@cedarjs/graphql-server 4.0.1-next.0 → 4.0.1-next.67
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/cjs/createGraphQLYoga.d.ts +2 -2
- package/dist/cjs/createGraphQLYoga.d.ts.map +1 -1
- package/dist/cjs/createGraphQLYoga.js +15 -1
- package/dist/cjs/functions/graphql.d.ts +1 -1
- package/dist/cjs/functions/graphql.d.ts.map +1 -1
- package/dist/cjs/functions/graphql.js +55 -2
- package/dist/cjs/plugins/useRedwoodAuthContext.d.ts.map +1 -1
- package/dist/cjs/plugins/useRedwoodAuthContext.js +20 -6
- package/dist/cjs/plugins/useRedwoodLogger.d.ts.map +1 -1
- package/dist/cjs/plugins/useRedwoodLogger.js +9 -2
- package/dist/cjs/types.d.ts +8 -4
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/createGraphQLYoga.d.ts +2 -2
- package/dist/createGraphQLYoga.d.ts.map +1 -1
- package/dist/createGraphQLYoga.js +5 -1
- package/dist/functions/graphql.d.ts +1 -1
- package/dist/functions/graphql.d.ts.map +1 -1
- package/dist/functions/graphql.js +45 -2
- package/dist/plugins/useRedwoodAuthContext.d.ts.map +1 -1
- package/dist/plugins/useRedwoodAuthContext.js +20 -6
- package/dist/plugins/useRedwoodLogger.d.ts.map +1 -1
- package/dist/plugins/useRedwoodLogger.js +9 -2
- package/dist/types.d.ts +8 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLYogaOptions } from './types.js';
|
|
2
|
-
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) => {
|
|
2
|
+
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<{
|
|
3
3
|
yoga: ServerAdapter<TServerContext, import("graphql-yoga").YogaServer<TServerContext, TUserContext>>;
|
|
4
4
|
logger: import("@cedarjs/api/logger").Logger;
|
|
5
|
-
}
|
|
5
|
+
}>;
|
|
6
6
|
//# sourceMappingURL=createGraphQLYoga.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGraphQLYoga.d.ts","sourceRoot":"","sources":["../../src/createGraphQLYoga.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,kBAAkB,EAAuB,MAAM,YAAY,CAAA;AAEzE,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"createGraphQLYoga.d.ts","sourceRoot":"","sources":["../../src/createGraphQLYoga.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,kBAAkB,EAAuB,MAAM,YAAY,CAAA;AAEzE,eAAO,MAAM,iBAAiB,GAAU,iVAwBrC,kBAAkB;;;EAgLpB,CAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var createGraphQLYoga_exports = {};
|
|
20
30
|
__export(createGraphQLYoga_exports, {
|
|
@@ -32,7 +42,7 @@ var import_introspection = require("./introspection.js");
|
|
|
32
42
|
var import_makeMergedSchema = require("./makeMergedSchema.js");
|
|
33
43
|
var import_plugins = require("./plugins/index.js");
|
|
34
44
|
var import_makeSubscriptions = require("./subscriptions/makeSubscriptions.js");
|
|
35
|
-
const createGraphQLYoga = ({
|
|
45
|
+
const createGraphQLYoga = async ({
|
|
36
46
|
healthCheckId = "yoga",
|
|
37
47
|
loggerConfig,
|
|
38
48
|
context,
|
|
@@ -92,6 +102,10 @@ const createGraphQLYoga = ({
|
|
|
92
102
|
}
|
|
93
103
|
try {
|
|
94
104
|
const plugins = [];
|
|
105
|
+
if (realtime) {
|
|
106
|
+
const { useCedarRealtime } = await import("@cedarjs/realtime");
|
|
107
|
+
plugins.push(useCedarRealtime(realtime));
|
|
108
|
+
}
|
|
95
109
|
const { disableIntrospection } = (0, import_introspection.configureGraphQLIntrospection)({
|
|
96
110
|
allowIntrospection
|
|
97
111
|
});
|
|
@@ -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+HpB,OAAO,oBAAoB,EAC3B,SAAS,aAAa,KACrB,OAAO,CAAC,GAAG,CAcf,CAAA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,14 +17,52 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var graphql_exports = {};
|
|
20
30
|
__export(graphql_exports, {
|
|
21
31
|
createGraphQLHandler: () => createGraphQLHandler
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(graphql_exports);
|
|
34
|
+
var cookie = __toESM(require("cookie"), 1);
|
|
35
|
+
var import_api = require("@cedarjs/api");
|
|
24
36
|
var import_store = require("@cedarjs/context/dist/store");
|
|
25
37
|
var import_createGraphQLYoga = require("../createGraphQLYoga.js");
|
|
38
|
+
function lambdaQueryToSearchParams(event) {
|
|
39
|
+
const query = new URLSearchParams();
|
|
40
|
+
if (event.multiValueQueryStringParameters) {
|
|
41
|
+
for (const [key, values] of Object.entries(
|
|
42
|
+
event.multiValueQueryStringParameters
|
|
43
|
+
)) {
|
|
44
|
+
if (values) {
|
|
45
|
+
for (const value of values) {
|
|
46
|
+
query.append(key, value);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} else if (event.queryStringParameters) {
|
|
51
|
+
for (const [key, value] of Object.entries(event.queryStringParameters)) {
|
|
52
|
+
if (value != null) {
|
|
53
|
+
query.set(key, value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return query;
|
|
58
|
+
}
|
|
59
|
+
function parseLambdaCookies(event) {
|
|
60
|
+
return new Map(
|
|
61
|
+
Object.entries(cookie.parse(event.headers?.cookie ?? "")).filter(
|
|
62
|
+
(entry) => entry[1] !== void 0
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
26
66
|
const createGraphQLHandler = ({
|
|
27
67
|
healthCheckId,
|
|
28
68
|
loggerConfig,
|
|
@@ -43,10 +83,11 @@ const createGraphQLHandler = ({
|
|
|
43
83
|
defaultError = "Something went wrong.",
|
|
44
84
|
graphiQLEndpoint = "/graphql",
|
|
45
85
|
schemaOptions,
|
|
86
|
+
realtime,
|
|
46
87
|
openTelemetryOptions,
|
|
47
88
|
trustedDocuments
|
|
48
89
|
}) => {
|
|
49
|
-
const
|
|
90
|
+
const yogaAndLoggerPromise = (0, import_createGraphQLYoga.createGraphQLYoga)({
|
|
50
91
|
healthCheckId,
|
|
51
92
|
loggerConfig,
|
|
52
93
|
context,
|
|
@@ -66,11 +107,13 @@ const createGraphQLHandler = ({
|
|
|
66
107
|
defaultError,
|
|
67
108
|
graphiQLEndpoint,
|
|
68
109
|
schemaOptions,
|
|
110
|
+
realtime,
|
|
69
111
|
openTelemetryOptions,
|
|
70
112
|
trustedDocuments
|
|
71
113
|
});
|
|
72
114
|
const handlerFn = async (event, requestContext) => {
|
|
73
115
|
requestContext.callbackWaitsForEmptyEventLoop = false;
|
|
116
|
+
const { yoga, logger } = await yogaAndLoggerPromise;
|
|
74
117
|
let lambdaResponse;
|
|
75
118
|
try {
|
|
76
119
|
const [, rest = ""] = event.path.split(graphiQLEndpoint);
|
|
@@ -92,7 +135,17 @@ const createGraphQLHandler = ({
|
|
|
92
135
|
},
|
|
93
136
|
{
|
|
94
137
|
event,
|
|
95
|
-
requestContext
|
|
138
|
+
requestContext,
|
|
139
|
+
cedarContext: {
|
|
140
|
+
params: event.pathParameters ?? {},
|
|
141
|
+
query: lambdaQueryToSearchParams(event),
|
|
142
|
+
cookies: parseLambdaCookies(event),
|
|
143
|
+
serverAuthState: await (0, import_api.getAuthenticationContext)({
|
|
144
|
+
authDecoder,
|
|
145
|
+
event,
|
|
146
|
+
context: requestContext
|
|
147
|
+
})
|
|
148
|
+
}
|
|
96
149
|
}
|
|
97
150
|
);
|
|
98
151
|
const responseHeaders = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedwoodAuthContext.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodAuthContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRedwoodAuthContext.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodAuthContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,EAAsB,OAAO,EAAE,MAAM,cAAc,CAAA;AAG/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAChC,gBAAgB,qBAAqB,CAAC,gBAAgB,CAAC,EACvD,cAAc,OAAO,GAAG,OAAO,EAAE,KAChC,MAAM,CAAC,mBAAmB,CAyC5B,CAAA"}
|
|
@@ -25,13 +25,16 @@ var import_api = require("@cedarjs/api");
|
|
|
25
25
|
const useRedwoodAuthContext = (getCurrentUser, authDecoder) => {
|
|
26
26
|
return {
|
|
27
27
|
async onContextBuilding({ context, extendContext }) {
|
|
28
|
-
let authContext =
|
|
28
|
+
let authContext = context.cedarContext?.serverAuthState;
|
|
29
29
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
if (!authContext) {
|
|
31
|
+
const authEvent = getAuthEvent(context);
|
|
32
|
+
authContext = await (0, import_api.getAuthenticationContext)({
|
|
33
|
+
authDecoder,
|
|
34
|
+
event: authEvent,
|
|
35
|
+
context: context.requestContext
|
|
36
|
+
});
|
|
37
|
+
}
|
|
35
38
|
} catch (error) {
|
|
36
39
|
throw new Error(
|
|
37
40
|
`Exception in getAuthenticationContext: ${error.message}`
|
|
@@ -54,6 +57,17 @@ const useRedwoodAuthContext = (getCurrentUser, authDecoder) => {
|
|
|
54
57
|
}
|
|
55
58
|
};
|
|
56
59
|
};
|
|
60
|
+
function getAuthEvent(context) {
|
|
61
|
+
if (context.request) {
|
|
62
|
+
return context.request;
|
|
63
|
+
}
|
|
64
|
+
if (context.event) {
|
|
65
|
+
return context.event;
|
|
66
|
+
}
|
|
67
|
+
throw new Error(
|
|
68
|
+
"GraphQL context contains neither a fetch-native Request nor a Lambda event. Please report this as a Cedar bug."
|
|
69
|
+
);
|
|
70
|
+
}
|
|
57
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
58
72
|
0 && (module.exports = {
|
|
59
73
|
useRedwoodAuthContext
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedwoodLogger.d.ts","sourceRoot":"","sources":["../../../src/plugins/useRedwoodLogger.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAI1C,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAGlE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD;;;;;;;;;;;;;GAaG;AACH,KAAK,oBAAoB,GAAG;IAC1B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,EAAE,eAAe,GAAG,MAAM,CAAA;IAEh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;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,oBAAoB,CAAA;CAC/B,CAAA;AA+DD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,cAAc,YAAY,KACzB,MAAM,CAAC,mBAAmB,CAgH5B,CAAA"}
|
|
@@ -122,10 +122,17 @@ const useRedwoodLogger = (loggerConfig) => {
|
|
|
122
122
|
options["query"] = args.variableValues;
|
|
123
123
|
}
|
|
124
124
|
if (includeRequestId) {
|
|
125
|
-
options["requestId"] =
|
|
125
|
+
options["requestId"] = // x-request-id is a widely adopted (though informal) HTTP header for
|
|
126
|
+
// distributed tracing. Load balancers, API gateways, and clients set
|
|
127
|
+
// it on each request so that all log lines for a single request can
|
|
128
|
+
// be correlated across services. We check it first so that an
|
|
129
|
+
// externally assigned ID is preserved end-to-end; if it is absent we
|
|
130
|
+
// fall back to the Lambda/API-Gateway request ID, and finally
|
|
131
|
+
// generate a UUID so there is always something to correlate on.
|
|
132
|
+
args.contextValue.request?.headers.get("x-request-id") || args.contextValue.requestContext?.awsRequestId || args.contextValue.event?.requestContext?.requestId || (0, import_uuid.v4)();
|
|
126
133
|
}
|
|
127
134
|
if (includeUserAgent) {
|
|
128
|
-
options["userAgent"] = args.contextValue.event?.headers["user-agent"];
|
|
135
|
+
options["userAgent"] = args.contextValue.request?.headers.get("user-agent") || args.contextValue.event?.headers["user-agent"];
|
|
129
136
|
}
|
|
130
137
|
const envelopLogger = childLogger.child({
|
|
131
138
|
...options
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import type { IExecutableSchemaDefinition } from '@graphql-tools/schema';
|
|
|
4
4
|
import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda';
|
|
5
5
|
import type { GraphQLObjectType, GraphQLInterfaceType, DocumentNode } from 'graphql';
|
|
6
6
|
import type { Plugin } from 'graphql-yoga';
|
|
7
|
-
import type { AuthContextPayload, Decoder } from '@cedarjs/api';
|
|
8
|
-
import type {
|
|
7
|
+
import type { AuthContextPayload, CorsConfig, Decoder } from '@cedarjs/api';
|
|
8
|
+
import type { CedarRequestContext } from '@cedarjs/api/runtime';
|
|
9
9
|
import type { CedarRealtimeOptions } from '@cedarjs/realtime';
|
|
10
10
|
import type { DirectiveGlobImports } from './directives/makeDirectives.js';
|
|
11
11
|
import type { useRedwoodDirectiveReturn, DirectivePluginOptions } from './plugins/useRedwoodDirective.js';
|
|
@@ -46,7 +46,9 @@ export type ArmorConfig = {
|
|
|
46
46
|
* This is an interface so you can extend it inside your application when needed
|
|
47
47
|
*/
|
|
48
48
|
export interface CedarGraphQLContext {
|
|
49
|
-
|
|
49
|
+
request?: Request;
|
|
50
|
+
cedarContext?: CedarRequestContext;
|
|
51
|
+
event?: APIGatewayProxyEvent;
|
|
50
52
|
requestContext?: LambdaContext | undefined;
|
|
51
53
|
currentUser?: ThenArg<ReturnType<GetCurrentUser>> | AuthContextPayload | null;
|
|
52
54
|
[index: string]: unknown;
|
|
@@ -56,7 +58,9 @@ export interface CedarGraphQLContext {
|
|
|
56
58
|
* @deprecated Please use CedarGraphQLContext
|
|
57
59
|
*/
|
|
58
60
|
export interface RedwoodGraphQLContext {
|
|
59
|
-
|
|
61
|
+
request?: Request;
|
|
62
|
+
cedarContext?: CedarRequestContext;
|
|
63
|
+
event?: APIGatewayProxyEvent;
|
|
60
64
|
requestContext: LambdaContext | undefined;
|
|
61
65
|
currentUser?: ThenArg<ReturnType<GetCurrentUser>> | AuthContextPayload | null;
|
|
62
66
|
[index: string]: unknown;
|
package/dist/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAE7D,OAAO,KAAK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;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAA;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,oBAAoB,CAAA;IAE/B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,6BAA6B,CAAA;IAEhD;;OAEG;IACH,oBAAoB,CAAC,EAAE,0BAA0B,CAAA;IAEjD;;;;;OAKG;IACH,cAAc,CAAC,EAAE,mBAAmB,CAAA;CACrC,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,CAAA;AAEtD,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,kBAAkB,EAClB,eAAe,GAAG,wBAAwB,CAC3C,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GraphQLYogaOptions } from './types.js';
|
|
2
|
-
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) => {
|
|
2
|
+
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<{
|
|
3
3
|
yoga: ServerAdapter<TServerContext, import("graphql-yoga").YogaServer<TServerContext, TUserContext>>;
|
|
4
4
|
logger: import("@cedarjs/api/logger").Logger;
|
|
5
|
-
}
|
|
5
|
+
}>;
|
|
6
6
|
//# sourceMappingURL=createGraphQLYoga.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGraphQLYoga.d.ts","sourceRoot":"","sources":["../src/createGraphQLYoga.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,kBAAkB,EAAuB,MAAM,YAAY,CAAA;AAEzE,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"createGraphQLYoga.d.ts","sourceRoot":"","sources":["../src/createGraphQLYoga.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,kBAAkB,EAAuB,MAAM,YAAY,CAAA;AAEzE,eAAO,MAAM,iBAAiB,GAAU,iVAwBrC,kBAAkB;;;EAgLpB,CAAA"}
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
useRedwoodTrustedDocuments
|
|
20
20
|
} from "./plugins/index.js";
|
|
21
21
|
import { makeSubscriptions } from "./subscriptions/makeSubscriptions.js";
|
|
22
|
-
const createGraphQLYoga = ({
|
|
22
|
+
const createGraphQLYoga = async ({
|
|
23
23
|
healthCheckId = "yoga",
|
|
24
24
|
loggerConfig,
|
|
25
25
|
context,
|
|
@@ -79,6 +79,10 @@ const createGraphQLYoga = ({
|
|
|
79
79
|
}
|
|
80
80
|
try {
|
|
81
81
|
const plugins = [];
|
|
82
|
+
if (realtime) {
|
|
83
|
+
const { useCedarRealtime } = await import("@cedarjs/realtime");
|
|
84
|
+
plugins.push(useCedarRealtime(realtime));
|
|
85
|
+
}
|
|
82
86
|
const { disableIntrospection } = configureGraphQLIntrospection({
|
|
83
87
|
allowIntrospection
|
|
84
88
|
});
|
|
@@ -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+HpB,OAAO,oBAAoB,EAC3B,SAAS,aAAa,KACrB,OAAO,CAAC,GAAG,CAcf,CAAA"}
|
|
@@ -1,5 +1,35 @@
|
|
|
1
|
+
import * as cookie from "cookie";
|
|
2
|
+
import { getAuthenticationContext } from "@cedarjs/api";
|
|
1
3
|
import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
|
|
2
4
|
import { createGraphQLYoga } from "../createGraphQLYoga.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 getAuthenticationContext({
|
|
111
|
+
authDecoder,
|
|
112
|
+
event,
|
|
113
|
+
context: requestContext
|
|
114
|
+
})
|
|
115
|
+
}
|
|
73
116
|
}
|
|
74
117
|
);
|
|
75
118
|
const responseHeaders = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedwoodAuthContext.d.ts","sourceRoot":"","sources":["../../src/plugins/useRedwoodAuthContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRedwoodAuthContext.d.ts","sourceRoot":"","sources":["../../src/plugins/useRedwoodAuthContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,EAAsB,OAAO,EAAE,MAAM,cAAc,CAAA;AAG/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE7E;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAChC,gBAAgB,qBAAqB,CAAC,gBAAgB,CAAC,EACvD,cAAc,OAAO,GAAG,OAAO,EAAE,KAChC,MAAM,CAAC,mBAAmB,CAyC5B,CAAA"}
|
|
@@ -2,13 +2,16 @@ import { getAuthenticationContext } from "@cedarjs/api";
|
|
|
2
2
|
const useRedwoodAuthContext = (getCurrentUser, authDecoder) => {
|
|
3
3
|
return {
|
|
4
4
|
async onContextBuilding({ context, extendContext }) {
|
|
5
|
-
let authContext =
|
|
5
|
+
let authContext = context.cedarContext?.serverAuthState;
|
|
6
6
|
try {
|
|
7
|
-
authContext
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
if (!authContext) {
|
|
8
|
+
const authEvent = getAuthEvent(context);
|
|
9
|
+
authContext = await getAuthenticationContext({
|
|
10
|
+
authDecoder,
|
|
11
|
+
event: authEvent,
|
|
12
|
+
context: context.requestContext
|
|
13
|
+
});
|
|
14
|
+
}
|
|
12
15
|
} catch (error) {
|
|
13
16
|
throw new Error(
|
|
14
17
|
`Exception in getAuthenticationContext: ${error.message}`
|
|
@@ -31,6 +34,17 @@ const useRedwoodAuthContext = (getCurrentUser, authDecoder) => {
|
|
|
31
34
|
}
|
|
32
35
|
};
|
|
33
36
|
};
|
|
37
|
+
function getAuthEvent(context) {
|
|
38
|
+
if (context.request) {
|
|
39
|
+
return context.request;
|
|
40
|
+
}
|
|
41
|
+
if (context.event) {
|
|
42
|
+
return context.event;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(
|
|
45
|
+
"GraphQL context contains neither a fetch-native Request nor a Lambda event. Please report this as a Cedar bug."
|
|
46
|
+
);
|
|
47
|
+
}
|
|
34
48
|
export {
|
|
35
49
|
useRedwoodAuthContext
|
|
36
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedwoodLogger.d.ts","sourceRoot":"","sources":["../../src/plugins/useRedwoodLogger.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAI1C,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAGlE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD;;;;;;;;;;;;;GAaG;AACH,KAAK,oBAAoB,GAAG;IAC1B;;;;;;;;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S,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,oBAAoB,CAAA;CAC/B,CAAA;AA+DD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAC3B,cAAc,YAAY,KACzB,MAAM,CAAC,mBAAmB,CAgH5B,CAAA"}
|
|
@@ -99,10 +99,17 @@ const useRedwoodLogger = (loggerConfig) => {
|
|
|
99
99
|
options["query"] = args.variableValues;
|
|
100
100
|
}
|
|
101
101
|
if (includeRequestId) {
|
|
102
|
-
options["requestId"] =
|
|
102
|
+
options["requestId"] = // x-request-id is a widely adopted (though informal) HTTP header for
|
|
103
|
+
// distributed tracing. Load balancers, API gateways, and clients set
|
|
104
|
+
// it on each request so that all log lines for a single request can
|
|
105
|
+
// be correlated across services. We check it first so that an
|
|
106
|
+
// externally assigned ID is preserved end-to-end; if it is absent we
|
|
107
|
+
// fall back to the Lambda/API-Gateway request ID, and finally
|
|
108
|
+
// generate a UUID so there is always something to correlate on.
|
|
109
|
+
args.contextValue.request?.headers.get("x-request-id") || args.contextValue.requestContext?.awsRequestId || args.contextValue.event?.requestContext?.requestId || uuidv4();
|
|
103
110
|
}
|
|
104
111
|
if (includeUserAgent) {
|
|
105
|
-
options["userAgent"] = args.contextValue.event?.headers["user-agent"];
|
|
112
|
+
options["userAgent"] = args.contextValue.request?.headers.get("user-agent") || args.contextValue.event?.headers["user-agent"];
|
|
106
113
|
}
|
|
107
114
|
const envelopLogger = childLogger.child({
|
|
108
115
|
...options
|
package/dist/types.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import type { IExecutableSchemaDefinition } from '@graphql-tools/schema';
|
|
|
4
4
|
import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda';
|
|
5
5
|
import type { GraphQLObjectType, GraphQLInterfaceType, DocumentNode } from 'graphql';
|
|
6
6
|
import type { Plugin } from 'graphql-yoga';
|
|
7
|
-
import type { AuthContextPayload, Decoder } from '@cedarjs/api';
|
|
8
|
-
import type {
|
|
7
|
+
import type { AuthContextPayload, CorsConfig, Decoder } from '@cedarjs/api';
|
|
8
|
+
import type { CedarRequestContext } from '@cedarjs/api/runtime';
|
|
9
9
|
import type { CedarRealtimeOptions } from '@cedarjs/realtime';
|
|
10
10
|
import type { DirectiveGlobImports } from './directives/makeDirectives.js';
|
|
11
11
|
import type { useRedwoodDirectiveReturn, DirectivePluginOptions } from './plugins/useRedwoodDirective.js';
|
|
@@ -46,7 +46,9 @@ export type ArmorConfig = {
|
|
|
46
46
|
* This is an interface so you can extend it inside your application when needed
|
|
47
47
|
*/
|
|
48
48
|
export interface CedarGraphQLContext {
|
|
49
|
-
|
|
49
|
+
request?: Request;
|
|
50
|
+
cedarContext?: CedarRequestContext;
|
|
51
|
+
event?: APIGatewayProxyEvent;
|
|
50
52
|
requestContext?: LambdaContext | undefined;
|
|
51
53
|
currentUser?: ThenArg<ReturnType<GetCurrentUser>> | AuthContextPayload | null;
|
|
52
54
|
[index: string]: unknown;
|
|
@@ -56,7 +58,9 @@ export interface CedarGraphQLContext {
|
|
|
56
58
|
* @deprecated Please use CedarGraphQLContext
|
|
57
59
|
*/
|
|
58
60
|
export interface RedwoodGraphQLContext {
|
|
59
|
-
|
|
61
|
+
request?: Request;
|
|
62
|
+
cedarContext?: CedarRequestContext;
|
|
63
|
+
event?: APIGatewayProxyEvent;
|
|
60
64
|
requestContext: LambdaContext | undefined;
|
|
61
65
|
currentUser?: ThenArg<ReturnType<GetCurrentUser>> | AuthContextPayload | null;
|
|
62
66
|
[index: string]: unknown;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,KAAK,EAAE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AGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAA;IAE/C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,oBAAoB,CAAA;IAE/B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,6BAA6B,CAAA;IAEhD;;OAEG;IACH,oBAAoB,CAAC,EAAE,0BAA0B,CAAA;IAEjD;;;;;OAKG;IACH,cAAc,CAAC,EAAE,mBAAmB,CAAA;CACrC,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,CAAA;AAEtD,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,kBAAkB,EAClB,eAAe,GAAG,wBAAwB,CAC3C,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/graphql-server",
|
|
3
|
-
"version": "4.0.1-next.
|
|
3
|
+
"version": "4.0.1-next.67+ad97a60c79",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -37,19 +37,20 @@
|
|
|
37
37
|
"test:watch": "yarn test --watch"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@cedarjs/api": "4.0.1-next.
|
|
41
|
-
"@cedarjs/context": "4.0.1-next.
|
|
40
|
+
"@cedarjs/api": "4.0.1-next.67+ad97a60c79",
|
|
41
|
+
"@cedarjs/context": "4.0.1-next.67+ad97a60c79",
|
|
42
42
|
"@envelop/core": "5.5.1",
|
|
43
43
|
"@envelop/depth-limit": "4.0.0",
|
|
44
44
|
"@envelop/disable-introspection": "6.0.0",
|
|
45
45
|
"@envelop/filter-operation-type": "6.0.0",
|
|
46
46
|
"@envelop/on-resolve": "4.1.1",
|
|
47
47
|
"@escape.tech/graphql-armor": "3.0.1",
|
|
48
|
-
"@graphql-tools/merge": "9.1.
|
|
49
|
-
"@graphql-tools/schema": "10.0.
|
|
48
|
+
"@graphql-tools/merge": "9.1.9",
|
|
49
|
+
"@graphql-tools/schema": "10.0.33",
|
|
50
50
|
"@graphql-tools/utils": "10.11.0",
|
|
51
51
|
"@graphql-yoga/plugin-persisted-operations": "3.21.0",
|
|
52
52
|
"@opentelemetry/api": "1.9.0",
|
|
53
|
+
"cookie": "1.1.1",
|
|
53
54
|
"graphql": "16.13.2",
|
|
54
55
|
"graphql-scalars": "1.25.0",
|
|
55
56
|
"graphql-tag": "2.12.6",
|
|
@@ -60,9 +61,9 @@
|
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@babel/cli": "7.28.6",
|
|
62
63
|
"@babel/core": "^7.26.10",
|
|
63
|
-
"@cedarjs/framework-tools": "4.0.1-next.
|
|
64
|
-
"@cedarjs/project-config": "4.0.1-next.
|
|
65
|
-
"@cedarjs/realtime": "4.0.1-next.
|
|
64
|
+
"@cedarjs/framework-tools": "4.0.1-next.67",
|
|
65
|
+
"@cedarjs/project-config": "4.0.1-next.67+ad97a60c79",
|
|
66
|
+
"@cedarjs/realtime": "4.0.1-next.67+ad97a60c79",
|
|
66
67
|
"@envelop/types": "5.2.1",
|
|
67
68
|
"@types/aws-lambda": "8.10.161",
|
|
68
69
|
"@types/jsonwebtoken": "9.0.10",
|
|
@@ -82,5 +83,5 @@
|
|
|
82
83
|
"publishConfig": {
|
|
83
84
|
"access": "public"
|
|
84
85
|
},
|
|
85
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "ad97a60c793c21b3263b4178e339d89406f7a7a3"
|
|
86
87
|
}
|