Skip to content

Commit 3ff7f59

Browse files
committed
Some fixes.
1 parent ef777d6 commit 3ff7f59

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/v2/providers/dataconnect.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,7 @@ export async function onGraphRequest(opts: GraphqlServerOptions): Promise<HttpsF
385385
invoker: "<FDC-P4SA>@developer.gserviceaccount.com",
386386
});
387387

388-
if (
389-
(await import("@apollo/server").then((mod) => !!mod)) &&
390-
(await import("@as-integrations/express4").then((mod) => !!mod))
391-
) {
388+
try {
392389
const { ApolloServer } = await import("@apollo/server");
393390
const { expressMiddleware } = await import("@as-integrations/express4");
394391
const serverPromise = (async () => {
@@ -409,9 +406,11 @@ export async function onGraphRequest(opts: GraphqlServerOptions): Promise<HttpsF
409406
const app = await serverPromise;
410407
app(req, res);
411408
});
412-
} else {
413-
// Handle case where optional-package is not available
414-
console.warn("Optional feature requires 'optional-package'.");
409+
} catch (e) {
410+
throw new Error(
411+
"'@apollo/server' and '@as-integrations/express4' are required to use for 'onGraphRequest'. Please add these dependencies to your project to use this feature: " +
412+
e
413+
);
415414
}
416415
}
417416

@@ -421,17 +420,17 @@ export interface GraphqlServerOptions {
421420
* A valid SDL string that represents the GraphQL server's schema.
422421
* Either `schema` or `schemaFilePath` is required.
423422
*/
424-
schema: string;
423+
schema?: string;
425424
/**
426425
* A file path to a valid GraphQL schema.
427426
* Either `schema` or `schemaFilePath` is required.
428427
*/
429-
schemaFilePath: string;
428+
schemaFilePath?: string;
430429
/**
431430
* The path where the GraphQL server will be served on the Cloud Run function.
432431
* If no path is provided, the server will be served at `/graphql`.
433432
*/
434-
path: string;
433+
path?: string;
435434
/** A map of functions that populate data for individual GraphQL schema fields. */
436435
resolvers: GraphqlResolvers;
437436
}
@@ -440,22 +439,22 @@ export interface GraphqlServerOptions {
440439
export interface FirebaseContext {
441440
auth?: {
442441
/** The UID of the Firebase user that made the request, if present. */
443-
uid: string;
442+
uid?: string;
444443
/** The token attached to the `X-Firebase-Auth-Token` in the request, if present. */
445-
token: string;
444+
token?: string;
446445
};
447446
}
448447

449448
export interface GraphqlResolvers {
450-
query: {
449+
query?: {
451450
[resolver: string]: (
452451
parent: unknown,
453452
args: Record<string, unknown>,
454453
context: FirebaseContext,
455454
info: GraphQLResolveInfo
456455
) => unknown;
457456
};
458-
mutation: {
457+
mutation?: {
459458
[key: string]: (
460459
parent: unknown,
461460
args: Record<string, unknown>,

0 commit comments

Comments
 (0)