···1-### This file was generated by Nexus Schema
2-### Do not make changes to this file directly
3-4-5-type Query {
6- build(src: String!): String
7- test(src: String!): String
8-}
···00000000
+30
.fluentci/sdk/builder.ts
···000000000000000000000000000000
···1+import { createGQLClient } from "./client.ts";
2+import { Context } from "./context.ts";
3+4+/**
5+ * @hidden
6+ *
7+ * Initialize a default client context from environment.
8+ */
9+export function initDefaultContext(): Context {
10+ let ctx = new Context();
11+12+ // Prefer DAGGER_SESSION_PORT if set
13+ const daggerSessionPort = Deno.env.get("DAGGER_SESSION_PORT");
14+ if (daggerSessionPort) {
15+ const sessionToken = Deno.env.get("DAGGER_SESSION_TOKEN");
16+ if (!sessionToken) {
17+ throw new Error(
18+ "DAGGER_SESSION_TOKEN must be set when using DAGGER_SESSION_PORT"
19+ );
20+ }
21+22+ ctx = new Context({
23+ client: createGQLClient(Number(daggerSessionPort), sessionToken),
24+ });
25+ } else {
26+ throw new Error("DAGGER_SESSION_PORT must be set");
27+ }
28+29+ return ctx;
30+}
···1+import { GraphQLClient } from "../deps.ts";
2+3+import { initDefaultContext } from "./builder.ts";
4+5+interface ContextConfig {
6+ client?: GraphQLClient;
7+}
8+9+/**
10+ * Context abstracts the connection to the engine.
11+ *
12+ * It's required to implement the default global SDK.
13+ * Its purpose is to store and returns the connection to the graphQL API, if
14+ * no connection is set, it can create its own.
15+ *
16+ * This is also useful for lazy evaluation with the default global client,
17+ * this one should only run the engine if it actually executes something.
18+ */
19+export class Context {
20+ private _client?: GraphQLClient;
21+22+ constructor(config?: ContextConfig) {
23+ this._client = config?.client;
24+ }
25+26+ /**
27+ * Returns a GraphQL client connected to the engine.
28+ *
29+ * If no client is set, it will create one.
30+ */
31+ public async connection(): Promise<GraphQLClient> {
32+ if (!this._client) {
33+ const defaultCtx = await initDefaultContext();
34+ this._client = defaultCtx._client as GraphQLClient;
35+ }
36+37+ return this._client;
38+ }
39+40+ /**
41+ * Close the connection and the engine if this one was started by the node
42+ * SDK.
43+ */
44+ public close(): void {
45+ // Reset client, so it can restart a new connection if necessary
46+ this._client = undefined;
47+ }
48+}
49+50+/**
51+ * Expose a default context for the global client
52+ */
53+export const defaultContext = new Context();