Skip to content

Commit b676280

Browse files
committed
Have onGraphRequest set a dataConnectHttpsTrigger instead of an httpsTrigger.
1 parent ad9f6fe commit b676280

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

spec/v2/providers/dataconnect.spec.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ describe("dataconnect", () => {
605605
});
606606

607607
describe("onGraphRequest", () => {
608-
it("returns callable function", () => {
608+
it("returns callable function with Data Connect trigger", () => {
609609
const opts = {
610610
schema: "type Query { hello: String }",
611611
schemaFilePath: "schema.gql",
@@ -616,12 +616,30 @@ describe("dataconnect", () => {
616616
},
617617
};
618618
const func = dataconnect.onGraphRequest(opts);
619-
expect(func.__trigger).to.deep.equal({
620-
platform: "gcfv2",
621-
httpsTrigger: {
622-
allowInsecure: false,
619+
expect(func.__endpoint).to.deep.equal({
620+
...expectedEndpointBase,
621+
dataConnectHttpsTrigger: {},
622+
});
623+
});
624+
it("returns callable function with request opts with Data Connect trigger", () => {
625+
const opts = {
626+
invoker: ["[email protected]"],
627+
region: "us-east4",
628+
schema: "type Query { hello: String }",
629+
schemaFilePath: "schema.gql",
630+
resolvers: {
631+
query: {
632+
hello: () => "Hello, world!",
633+
},
634+
},
635+
};
636+
const func = dataconnect.onGraphRequest(opts);
637+
expect(func.__endpoint).to.deep.equal({
638+
...expectedEndpointBase,
639+
dataConnectHttpsTrigger: {
640+
invoker: ["[email protected]"],
623641
},
624-
labels: {},
642+
region: ["us-east4"],
625643
});
626644
});
627645
});

src/runtime/manifest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export interface ManifestEndpoint {
7171
genkitAction?: string;
7272
};
7373

74+
dataConnectHttpsTrigger?: {
75+
invoker?: string[];
76+
};
77+
7478
eventTrigger?: {
7579
eventFilters: Record<string, string | Expression<string>>;
7680
eventFilterPathPatterns?: Record<string, string | Expression<string>>;

src/v2/providers/dataconnect.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import cors from "cors";
2424
import express from "express";
2525
import fs from "fs";
2626
import { GraphQLResolveInfo } from "graphql";
27-
import { HttpsFunction, onRequest } from "./https";
27+
import { HttpsFunction, HttpsOptions, onRequest } from "./https";
2828
import { CloudEvent, CloudFunction } from "../core";
2929
import { ParamsOf, VarName } from "../../common/params";
3030
import {
@@ -423,15 +423,22 @@ let serverPromise: Promise<express.Express> | null = null;
423423
* @returns {HttpsFunction} A function you can export and deploy.
424424
*/
425425
export function onGraphRequest(opts: GraphqlServerOptions): HttpsFunction {
426-
return onRequest(async (req, res) => {
426+
const func = onRequest(opts, async (req, res) => {
427427
serverPromise = serverPromise ?? initGraphqlServer(opts);
428428
const app = await serverPromise;
429429
app(req, res);
430430
});
431+
func.__endpoint.dataConnectHttpsTrigger = {};
432+
const invoker = func.__endpoint.httpsTrigger?.invoker;
433+
if (invoker && invoker.length) {
434+
func.__endpoint.dataConnectHttpsTrigger.invoker = invoker;
435+
}
436+
delete func.__endpoint.httpsTrigger;
437+
return func;
431438
}
432439

433440
/** Options for configuring the GraphQL server. */
434-
export interface GraphqlServerOptions {
441+
export interface GraphqlServerOptions extends HttpsOptions {
435442
/**
436443
* A valid SDL string that represents the GraphQL server's schema.
437444
* Either `schema` or `schemaFilePath` is required.

0 commit comments

Comments
 (0)