@executor-js/plugin-graphql 0.1.0 → 1.4.20
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/AddGraphqlSource-3Z3DB4KQ.js +239 -0
- package/dist/AddGraphqlSource-3Z3DB4KQ.js.map +1 -0
- package/dist/EditGraphqlSource-F37RPNKV.js +251 -0
- package/dist/EditGraphqlSource-F37RPNKV.js.map +1 -0
- package/dist/GraphqlSourceSummary-6EYBXVD2.js +70 -0
- package/dist/GraphqlSourceSummary-6EYBXVD2.js.map +1 -0
- package/dist/api/group.d.ts +204 -13
- package/dist/api/handlers.d.ts +51 -3
- package/dist/api/index.d.ts +482 -0
- package/dist/chunk-445ZPXHU.js +148 -0
- package/dist/chunk-445ZPXHU.js.map +1 -0
- package/dist/chunk-EW4Y3KEX.js +182 -0
- package/dist/chunk-EW4Y3KEX.js.map +1 -0
- package/dist/chunk-M4SJY6CB.js +45 -0
- package/dist/chunk-M4SJY6CB.js.map +1 -0
- package/dist/chunk-PO2TPM5B.js +1636 -0
- package/dist/chunk-PO2TPM5B.js.map +1 -0
- package/dist/client.js +75 -0
- package/dist/client.js.map +1 -0
- package/dist/core.js +32 -10
- package/dist/index.js +2 -1
- package/dist/react/GraphqlSourceFields.d.ts +8 -0
- package/dist/react/GraphqlSourceSummary.d.ts +3 -1
- package/dist/react/atoms.d.ts +206 -10
- package/dist/react/client.d.ts +200 -12
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/introspect.d.ts +437 -43
- package/dist/sdk/invoke.d.ts +17 -3
- package/dist/sdk/plugin.d.ts +192 -170
- package/dist/sdk/store.d.ts +84 -11
- package/dist/sdk/types.d.ts +129 -30
- package/dist/testing/index.d.ts +52 -0
- package/dist/testing.js +131 -0
- package/dist/testing.js.map +1 -0
- package/package.json +18 -4
- package/dist/chunk-EIC5WI6C.js +0 -1225
- package/dist/chunk-EIC5WI6C.js.map +0 -1
package/dist/sdk/types.d.ts
CHANGED
|
@@ -1,45 +1,62 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
export declare const GraphqlOperationKind: Schema.Literals<readonly ["query", "mutation"]>;
|
|
3
3
|
export type GraphqlOperationKind = typeof GraphqlOperationKind.Type;
|
|
4
|
-
declare const
|
|
4
|
+
export declare const GraphqlArgument: Schema.Struct<{
|
|
5
5
|
readonly name: Schema.String;
|
|
6
6
|
readonly typeName: Schema.String;
|
|
7
7
|
readonly required: Schema.Boolean;
|
|
8
8
|
readonly description: Schema.OptionFromOptional<Schema.String>;
|
|
9
|
-
}
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
declare const ExtractedField_base: Schema.Class<ExtractedField, Schema.Struct<{
|
|
9
|
+
}>;
|
|
10
|
+
export type GraphqlArgument = typeof GraphqlArgument.Type;
|
|
11
|
+
export declare const ExtractedField: Schema.Struct<{
|
|
13
12
|
/** e.g. "user", "createUser" */
|
|
14
13
|
readonly fieldName: Schema.String;
|
|
15
14
|
/** "query" or "mutation" */
|
|
16
15
|
readonly kind: Schema.Literals<readonly ["query", "mutation"]>;
|
|
17
16
|
readonly description: Schema.OptionFromOptional<Schema.String>;
|
|
18
|
-
readonly arguments: Schema.$Array<
|
|
17
|
+
readonly arguments: Schema.$Array<Schema.Struct<{
|
|
18
|
+
readonly name: Schema.String;
|
|
19
|
+
readonly typeName: Schema.String;
|
|
20
|
+
readonly required: Schema.Boolean;
|
|
21
|
+
readonly description: Schema.OptionFromOptional<Schema.String>;
|
|
22
|
+
}>>;
|
|
19
23
|
/** JSON Schema for the input (built from arguments) */
|
|
20
24
|
readonly inputSchema: Schema.OptionFromOptional<Schema.Unknown>;
|
|
21
25
|
/** The return type name for documentation */
|
|
22
26
|
readonly returnTypeName: Schema.String;
|
|
23
|
-
}
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
declare const ExtractionResult_base: Schema.Class<ExtractionResult, Schema.Struct<{
|
|
27
|
+
}>;
|
|
28
|
+
export type ExtractedField = typeof ExtractedField.Type;
|
|
29
|
+
export declare const ExtractionResult: Schema.Struct<{
|
|
27
30
|
/** Schema name from introspection */
|
|
28
31
|
readonly schemaName: Schema.OptionFromOptional<Schema.String>;
|
|
29
|
-
readonly fields: Schema.$Array<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
readonly fields: Schema.$Array<Schema.Struct<{
|
|
33
|
+
/** e.g. "user", "createUser" */
|
|
34
|
+
readonly fieldName: Schema.String;
|
|
35
|
+
/** "query" or "mutation" */
|
|
36
|
+
readonly kind: Schema.Literals<readonly ["query", "mutation"]>;
|
|
37
|
+
readonly description: Schema.OptionFromOptional<Schema.String>;
|
|
38
|
+
readonly arguments: Schema.$Array<Schema.Struct<{
|
|
39
|
+
readonly name: Schema.String;
|
|
40
|
+
readonly typeName: Schema.String;
|
|
41
|
+
readonly required: Schema.Boolean;
|
|
42
|
+
readonly description: Schema.OptionFromOptional<Schema.String>;
|
|
43
|
+
}>>;
|
|
44
|
+
/** JSON Schema for the input (built from arguments) */
|
|
45
|
+
readonly inputSchema: Schema.OptionFromOptional<Schema.Unknown>;
|
|
46
|
+
/** The return type name for documentation */
|
|
47
|
+
readonly returnTypeName: Schema.String;
|
|
48
|
+
}>>;
|
|
49
|
+
}>;
|
|
50
|
+
export type ExtractionResult = typeof ExtractionResult.Type;
|
|
51
|
+
export declare const OperationBinding: Schema.Struct<{
|
|
34
52
|
readonly kind: Schema.Literals<readonly ["query", "mutation"]>;
|
|
35
53
|
readonly fieldName: Schema.String;
|
|
36
54
|
/** The full GraphQL query/mutation string */
|
|
37
55
|
readonly operationString: Schema.String;
|
|
38
56
|
/** Ordered variable names for mapping */
|
|
39
57
|
readonly variableNames: Schema.$Array<Schema.String>;
|
|
40
|
-
}
|
|
41
|
-
export
|
|
42
|
-
}
|
|
58
|
+
}>;
|
|
59
|
+
export type OperationBinding = typeof OperationBinding.Type;
|
|
43
60
|
export declare const HeaderValue: Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
44
61
|
readonly secretId: Schema.String;
|
|
45
62
|
readonly prefix: Schema.optional<Schema.String>;
|
|
@@ -50,34 +67,116 @@ export declare const QueryParamValue: Schema.Union<readonly [Schema.String, Sche
|
|
|
50
67
|
readonly prefix: Schema.optional<Schema.String>;
|
|
51
68
|
}>]>;
|
|
52
69
|
export type QueryParamValue = typeof QueryParamValue.Type;
|
|
70
|
+
export declare const ConfiguredGraphqlCredentialValue: Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
71
|
+
readonly kind: Schema.Literal<"binding">;
|
|
72
|
+
readonly slot: Schema.String;
|
|
73
|
+
readonly prefix: Schema.optional<Schema.String>;
|
|
74
|
+
}>]>;
|
|
75
|
+
export type ConfiguredGraphqlCredentialValue = typeof ConfiguredGraphqlCredentialValue.Type;
|
|
76
|
+
export declare const GraphqlCredentialInput: Schema.Union<readonly [Schema.Struct<{
|
|
77
|
+
readonly secretId: Schema.String;
|
|
78
|
+
readonly prefix: Schema.optional<Schema.String>;
|
|
79
|
+
readonly targetScope: Schema.brand<Schema.String, "ScopeId">;
|
|
80
|
+
readonly secretScopeId: Schema.optional<Schema.brand<Schema.String, "ScopeId">>;
|
|
81
|
+
}>, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
82
|
+
readonly secretId: Schema.String;
|
|
83
|
+
readonly prefix: Schema.optional<Schema.String>;
|
|
84
|
+
}>]>, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
85
|
+
readonly kind: Schema.Literal<"binding">;
|
|
86
|
+
readonly slot: Schema.String;
|
|
87
|
+
readonly prefix: Schema.optional<Schema.String>;
|
|
88
|
+
}>]>]>;
|
|
89
|
+
export type GraphqlCredentialInput = typeof GraphqlCredentialInput.Type;
|
|
90
|
+
export declare const graphqlHeaderSlot: (name: string) => string;
|
|
91
|
+
export declare const graphqlQueryParamSlot: (name: string) => string;
|
|
92
|
+
export declare const GRAPHQL_OAUTH_CONNECTION_SLOT = "auth:oauth2:connection";
|
|
53
93
|
export declare const GraphqlSourceAuth: Schema.Union<readonly [Schema.Struct<{
|
|
54
94
|
readonly kind: Schema.Literal<"none">;
|
|
55
95
|
}>, Schema.Struct<{
|
|
56
96
|
readonly kind: Schema.Literal<"oauth2">;
|
|
57
|
-
readonly
|
|
97
|
+
readonly connectionSlot: Schema.String;
|
|
58
98
|
}>]>;
|
|
59
99
|
export type GraphqlSourceAuth = typeof GraphqlSourceAuth.Type;
|
|
60
|
-
declare const
|
|
100
|
+
export declare const GraphqlSourceAuthInput: Schema.Union<readonly [Schema.Union<readonly [Schema.Struct<{
|
|
101
|
+
readonly kind: Schema.Literal<"none">;
|
|
102
|
+
}>, Schema.Struct<{
|
|
103
|
+
readonly kind: Schema.Literal<"oauth2">;
|
|
104
|
+
readonly connectionSlot: Schema.String;
|
|
105
|
+
}>]>, Schema.Struct<{
|
|
106
|
+
readonly kind: Schema.Literal<"oauth2">;
|
|
107
|
+
readonly connectionId: Schema.String;
|
|
108
|
+
}>]>;
|
|
109
|
+
export type GraphqlSourceAuthInput = typeof GraphqlSourceAuthInput.Type;
|
|
110
|
+
export declare const GraphqlSourceBindingValue: Schema.Union<readonly [Schema.Struct<{
|
|
111
|
+
readonly kind: Schema.Literal<"text">;
|
|
112
|
+
readonly text: Schema.String;
|
|
113
|
+
}>, Schema.Struct<{
|
|
114
|
+
readonly kind: Schema.Literal<"secret">;
|
|
115
|
+
readonly secretId: Schema.brand<Schema.String, "SecretId">;
|
|
116
|
+
readonly secretScopeId: Schema.optional<Schema.brand<Schema.String, "ScopeId">>;
|
|
117
|
+
}>, Schema.Struct<{
|
|
118
|
+
readonly kind: Schema.Literal<"connection">;
|
|
119
|
+
readonly connectionId: Schema.brand<Schema.String, "ConnectionId">;
|
|
120
|
+
}>]>;
|
|
121
|
+
export type GraphqlSourceBindingValue = typeof GraphqlSourceBindingValue.Type;
|
|
122
|
+
export declare const GraphqlSourceBindingInput: Schema.Struct<{
|
|
123
|
+
readonly sourceId: Schema.String;
|
|
124
|
+
readonly sourceScope: Schema.brand<Schema.String, "ScopeId">;
|
|
125
|
+
readonly scope: Schema.brand<Schema.String, "ScopeId">;
|
|
126
|
+
readonly slot: Schema.String;
|
|
127
|
+
readonly value: Schema.Union<readonly [Schema.Struct<{
|
|
128
|
+
readonly kind: Schema.Literal<"text">;
|
|
129
|
+
readonly text: Schema.String;
|
|
130
|
+
}>, Schema.Struct<{
|
|
131
|
+
readonly kind: Schema.Literal<"secret">;
|
|
132
|
+
readonly secretId: Schema.brand<Schema.String, "SecretId">;
|
|
133
|
+
readonly secretScopeId: Schema.optional<Schema.brand<Schema.String, "ScopeId">>;
|
|
134
|
+
}>, Schema.Struct<{
|
|
135
|
+
readonly kind: Schema.Literal<"connection">;
|
|
136
|
+
readonly connectionId: Schema.brand<Schema.String, "ConnectionId">;
|
|
137
|
+
}>]>;
|
|
138
|
+
}>;
|
|
139
|
+
export type GraphqlSourceBindingInput = typeof GraphqlSourceBindingInput.Type;
|
|
140
|
+
export declare const GraphqlSourceBindingRef: Schema.Struct<{
|
|
141
|
+
readonly sourceId: Schema.String;
|
|
142
|
+
readonly sourceScopeId: Schema.brand<Schema.String, "ScopeId">;
|
|
143
|
+
readonly scopeId: Schema.brand<Schema.String, "ScopeId">;
|
|
144
|
+
readonly slot: Schema.String;
|
|
145
|
+
readonly value: Schema.Union<readonly [Schema.Struct<{
|
|
146
|
+
readonly kind: Schema.Literal<"text">;
|
|
147
|
+
readonly text: Schema.String;
|
|
148
|
+
}>, Schema.Struct<{
|
|
149
|
+
readonly kind: Schema.Literal<"secret">;
|
|
150
|
+
readonly secretId: Schema.brand<Schema.String, "SecretId">;
|
|
151
|
+
readonly secretScopeId: Schema.optional<Schema.brand<Schema.String, "ScopeId">>;
|
|
152
|
+
}>, Schema.Struct<{
|
|
153
|
+
readonly kind: Schema.Literal<"connection">;
|
|
154
|
+
readonly connectionId: Schema.brand<Schema.String, "ConnectionId">;
|
|
155
|
+
}>]>;
|
|
156
|
+
readonly createdAt: Schema.Date;
|
|
157
|
+
readonly updatedAt: Schema.Date;
|
|
158
|
+
}>;
|
|
159
|
+
export type GraphqlSourceBindingRef = typeof GraphqlSourceBindingRef.Type;
|
|
160
|
+
export declare const InvocationConfig: Schema.Struct<{
|
|
61
161
|
/** The GraphQL endpoint URL */
|
|
62
162
|
readonly endpoint: Schema.String;
|
|
63
163
|
/** Headers applied to every request. Values can reference secrets. */
|
|
64
164
|
readonly headers: Schema.withConstructorDefault<Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
65
|
-
readonly
|
|
165
|
+
readonly kind: Schema.Literal<"binding">;
|
|
166
|
+
readonly slot: Schema.String;
|
|
66
167
|
readonly prefix: Schema.optional<Schema.String>;
|
|
67
168
|
}>]>>>>;
|
|
68
169
|
/** Query parameters applied to every request. Values can reference secrets. */
|
|
69
170
|
readonly queryParams: Schema.withConstructorDefault<Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Struct<{
|
|
70
|
-
readonly
|
|
171
|
+
readonly kind: Schema.Literal<"binding">;
|
|
172
|
+
readonly slot: Schema.String;
|
|
71
173
|
readonly prefix: Schema.optional<Schema.String>;
|
|
72
174
|
}>]>>>>;
|
|
73
|
-
}
|
|
74
|
-
export
|
|
75
|
-
|
|
76
|
-
declare const InvocationResult_base: Schema.Class<InvocationResult, Schema.Struct<{
|
|
175
|
+
}>;
|
|
176
|
+
export type InvocationConfig = typeof InvocationConfig.Type;
|
|
177
|
+
export declare const InvocationResult: Schema.Struct<{
|
|
77
178
|
readonly status: Schema.Number;
|
|
78
179
|
readonly data: Schema.NullOr<Schema.Unknown>;
|
|
79
180
|
readonly errors: Schema.NullOr<Schema.Unknown>;
|
|
80
|
-
}
|
|
81
|
-
export
|
|
82
|
-
}
|
|
83
|
-
export {};
|
|
181
|
+
}>;
|
|
182
|
+
export type InvocationResult = typeof InvocationResult.Type;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Schema as EffectSchema, Scope } from "effect";
|
|
2
|
+
import { GraphQLSchema } from "graphql";
|
|
3
|
+
declare const GraphqlRequestPayload: EffectSchema.Struct<{
|
|
4
|
+
readonly query: EffectSchema.optional<EffectSchema.String>;
|
|
5
|
+
readonly variables: EffectSchema.optional<EffectSchema.$Record<EffectSchema.String, EffectSchema.Unknown>>;
|
|
6
|
+
readonly operationName: EffectSchema.optional<EffectSchema.NullOr<EffectSchema.String>>;
|
|
7
|
+
}>;
|
|
8
|
+
type GraphqlRequestPayload = typeof GraphqlRequestPayload.Type;
|
|
9
|
+
export interface GraphqlTestRequest {
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly method: string;
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
14
|
+
readonly payload: GraphqlRequestPayload;
|
|
15
|
+
}
|
|
16
|
+
export interface GraphqlTestContext {
|
|
17
|
+
readonly request: GraphqlTestRequest;
|
|
18
|
+
}
|
|
19
|
+
export interface GraphqlTestServerOptions {
|
|
20
|
+
readonly schema: GraphQLSchema;
|
|
21
|
+
readonly path?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface GraphqlTestServerShape {
|
|
24
|
+
readonly endpoint: string;
|
|
25
|
+
readonly schema: GraphQLSchema;
|
|
26
|
+
readonly requests: Effect.Effect<readonly GraphqlTestRequest[]>;
|
|
27
|
+
readonly clearRequests: Effect.Effect<void>;
|
|
28
|
+
}
|
|
29
|
+
declare const GraphqlTestServerAddressError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
30
|
+
readonly _tag: "GraphqlTestServerAddressError";
|
|
31
|
+
} & Readonly<A>;
|
|
32
|
+
declare class GraphqlTestServerAddressError extends GraphqlTestServerAddressError_base<{
|
|
33
|
+
readonly address: unknown;
|
|
34
|
+
}> {
|
|
35
|
+
}
|
|
36
|
+
declare const GraphqlTestServerHandlerError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
37
|
+
readonly _tag: "GraphqlTestServerHandlerError";
|
|
38
|
+
} & Readonly<A>;
|
|
39
|
+
declare class GraphqlTestServerHandlerError extends GraphqlTestServerHandlerError_base<{
|
|
40
|
+
readonly cause: unknown;
|
|
41
|
+
}> {
|
|
42
|
+
}
|
|
43
|
+
export declare const serveGraphqlTestServer: (options: GraphqlTestServerOptions) => Effect.Effect<GraphqlTestServerShape, GraphqlTestServerAddressError | GraphqlTestServerHandlerError, Scope.Scope>;
|
|
44
|
+
declare const GraphqlTestServer_base: Context.ServiceClass<GraphqlTestServer, "@executor-js/plugin-graphql/testing/GraphqlTestServer", GraphqlTestServerShape>;
|
|
45
|
+
export declare class GraphqlTestServer extends GraphqlTestServer_base {
|
|
46
|
+
static readonly layer: (options: GraphqlTestServerOptions) => Layer.Layer<GraphqlTestServer, GraphqlTestServerAddressError | GraphqlTestServerHandlerError, never>;
|
|
47
|
+
}
|
|
48
|
+
export declare const makeGreetingGraphqlSchema: () => GraphQLSchema;
|
|
49
|
+
export declare const TestLayers: {
|
|
50
|
+
greeting: () => Layer.Layer<GraphqlTestServer, GraphqlTestServerAddressError | GraphqlTestServerHandlerError, never>;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// src/testing/index.ts
|
|
2
|
+
import {
|
|
3
|
+
Context,
|
|
4
|
+
Data,
|
|
5
|
+
Effect,
|
|
6
|
+
Layer,
|
|
7
|
+
Predicate,
|
|
8
|
+
Ref,
|
|
9
|
+
Schema as EffectSchema
|
|
10
|
+
} from "effect";
|
|
11
|
+
import { HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
12
|
+
import { GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLString } from "graphql";
|
|
13
|
+
import { createYoga } from "graphql-yoga";
|
|
14
|
+
import { serveTestHttpApp } from "@executor-js/sdk/testing";
|
|
15
|
+
var GraphqlRequestPayload = EffectSchema.Struct({
|
|
16
|
+
query: EffectSchema.optional(EffectSchema.String),
|
|
17
|
+
variables: EffectSchema.optional(EffectSchema.Record(EffectSchema.String, EffectSchema.Unknown)),
|
|
18
|
+
operationName: EffectSchema.optional(EffectSchema.NullOr(EffectSchema.String))
|
|
19
|
+
});
|
|
20
|
+
var GraphqlTestServerAddressError = class extends Data.TaggedError("GraphqlTestServerAddressError") {
|
|
21
|
+
};
|
|
22
|
+
var GraphqlTestServerHandlerError = class extends Data.TaggedError("GraphqlTestServerHandlerError") {
|
|
23
|
+
};
|
|
24
|
+
var headersFromRequest = (headers) => Object.fromEntries(headers.entries());
|
|
25
|
+
var payloadFromParams = (params) => ({
|
|
26
|
+
query: params.query,
|
|
27
|
+
variables: typeof params.variables === "object" && params.variables !== null ? params.variables : void 0,
|
|
28
|
+
operationName: params.operationName ?? null
|
|
29
|
+
});
|
|
30
|
+
var captureRequest = (initial, requests) => {
|
|
31
|
+
const url = new URL(initial.request.url);
|
|
32
|
+
const captured = {
|
|
33
|
+
url: initial.request.url,
|
|
34
|
+
method: initial.request.method,
|
|
35
|
+
path: url.pathname,
|
|
36
|
+
headers: headersFromRequest(initial.request.headers),
|
|
37
|
+
payload: payloadFromParams(initial.params)
|
|
38
|
+
};
|
|
39
|
+
return Effect.runPromise(
|
|
40
|
+
Ref.update(requests, (all) => [...all, captured]).pipe(Effect.as(captured))
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
var serveGraphqlTestServer = (options) => Effect.gen(function* () {
|
|
44
|
+
const requests = yield* Ref.make([]);
|
|
45
|
+
const path = options.path ?? "/graphql";
|
|
46
|
+
const yoga = createYoga({
|
|
47
|
+
schema: options.schema,
|
|
48
|
+
graphqlEndpoint: path,
|
|
49
|
+
graphiql: false,
|
|
50
|
+
landingPage: false,
|
|
51
|
+
logging: false,
|
|
52
|
+
maskedErrors: false,
|
|
53
|
+
context: (initial) => captureRequest(initial, requests).then((request) => ({
|
|
54
|
+
request
|
|
55
|
+
}))
|
|
56
|
+
});
|
|
57
|
+
const server = yield* serveTestHttpApp(
|
|
58
|
+
(request) => Effect.gen(function* () {
|
|
59
|
+
const webRequest = yield* HttpServerRequest.toWeb(request);
|
|
60
|
+
const response = yield* Effect.promise(() => Promise.resolve(yoga.handle(webRequest, {})));
|
|
61
|
+
return HttpServerResponse.fromWeb(response);
|
|
62
|
+
}).pipe(
|
|
63
|
+
Effect.catch(
|
|
64
|
+
() => Effect.succeed(
|
|
65
|
+
HttpServerResponse.text("GraphQL test server failed", {
|
|
66
|
+
status: 500,
|
|
67
|
+
contentType: "text/plain"
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
).pipe(
|
|
73
|
+
Effect.mapError(
|
|
74
|
+
(error) => Predicate.isTagged(error, "TestHttpServerAddressError") ? new GraphqlTestServerAddressError({ address: error.address }) : new GraphqlTestServerHandlerError({ cause: error.cause })
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
return {
|
|
78
|
+
endpoint: server.url(path),
|
|
79
|
+
schema: options.schema,
|
|
80
|
+
requests: Ref.get(requests),
|
|
81
|
+
clearRequests: Ref.set(requests, [])
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
var GraphqlTestServer = class _GraphqlTestServer extends Context.Service()(
|
|
85
|
+
"@executor-js/plugin-graphql/testing/GraphqlTestServer"
|
|
86
|
+
) {
|
|
87
|
+
static layer = (options) => Layer.effect(_GraphqlTestServer, serveGraphqlTestServer(options));
|
|
88
|
+
};
|
|
89
|
+
var stringArgument = (args, key, fallback) => {
|
|
90
|
+
const value = args[key];
|
|
91
|
+
return typeof value === "string" ? value : fallback;
|
|
92
|
+
};
|
|
93
|
+
var makeGreetingGraphqlSchema = () => {
|
|
94
|
+
const Query = new GraphQLObjectType({
|
|
95
|
+
name: "Query",
|
|
96
|
+
fields: {
|
|
97
|
+
hello: {
|
|
98
|
+
type: GraphQLString,
|
|
99
|
+
description: "Say hello",
|
|
100
|
+
args: {
|
|
101
|
+
name: { type: GraphQLString }
|
|
102
|
+
},
|
|
103
|
+
resolve: (_source, args) => `Hello ${stringArgument(args, "name", "world")}`
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const Mutation = new GraphQLObjectType({
|
|
108
|
+
name: "Mutation",
|
|
109
|
+
fields: {
|
|
110
|
+
setGreeting: {
|
|
111
|
+
type: GraphQLString,
|
|
112
|
+
description: "Set greeting message",
|
|
113
|
+
args: {
|
|
114
|
+
message: { type: new GraphQLNonNull(GraphQLString) }
|
|
115
|
+
},
|
|
116
|
+
resolve: (_source, args) => stringArgument(args, "message", "")
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return new GraphQLSchema({ query: Query, mutation: Mutation });
|
|
121
|
+
};
|
|
122
|
+
var TestLayers = {
|
|
123
|
+
greeting: () => GraphqlTestServer.layer({ schema: makeGreetingGraphqlSchema() })
|
|
124
|
+
};
|
|
125
|
+
export {
|
|
126
|
+
GraphqlTestServer,
|
|
127
|
+
TestLayers,
|
|
128
|
+
makeGreetingGraphqlSchema,
|
|
129
|
+
serveGraphqlTestServer
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing/index.ts"],"sourcesContent":["import {\n Context,\n Data,\n Effect,\n Layer,\n Predicate,\n Ref,\n Schema as EffectSchema,\n Scope,\n} from \"effect\";\nimport { HttpServerRequest, HttpServerResponse } from \"effect/unstable/http\";\nimport { GraphQLNonNull, GraphQLObjectType, GraphQLSchema, GraphQLString } from \"graphql\";\nimport { createYoga, type GraphQLParams, type YogaInitialContext } from \"graphql-yoga\";\nimport { serveTestHttpApp } from \"@executor-js/sdk/testing\";\n\nconst GraphqlRequestPayload = EffectSchema.Struct({\n query: EffectSchema.optional(EffectSchema.String),\n variables: EffectSchema.optional(EffectSchema.Record(EffectSchema.String, EffectSchema.Unknown)),\n operationName: EffectSchema.optional(EffectSchema.NullOr(EffectSchema.String)),\n});\n\ntype GraphqlRequestPayload = typeof GraphqlRequestPayload.Type;\n\nexport interface GraphqlTestRequest {\n readonly url: string;\n readonly method: string;\n readonly path: string;\n readonly headers: Readonly<Record<string, string>>;\n readonly payload: GraphqlRequestPayload;\n}\n\nexport interface GraphqlTestContext {\n readonly request: GraphqlTestRequest;\n}\n\nexport interface GraphqlTestServerOptions {\n readonly schema: GraphQLSchema;\n readonly path?: string;\n}\n\nexport interface GraphqlTestServerShape {\n readonly endpoint: string;\n readonly schema: GraphQLSchema;\n readonly requests: Effect.Effect<readonly GraphqlTestRequest[]>;\n readonly clearRequests: Effect.Effect<void>;\n}\n\nclass GraphqlTestServerAddressError extends Data.TaggedError(\"GraphqlTestServerAddressError\")<{\n readonly address: unknown;\n}> {}\n\nclass GraphqlTestServerHandlerError extends Data.TaggedError(\"GraphqlTestServerHandlerError\")<{\n readonly cause: unknown;\n}> {}\n\nconst headersFromRequest = (headers: Headers): Readonly<Record<string, string>> =>\n Object.fromEntries(headers.entries());\n\nconst payloadFromParams = (params: GraphQLParams): GraphqlRequestPayload => ({\n query: params.query,\n variables:\n typeof params.variables === \"object\" && params.variables !== null\n ? params.variables\n : undefined,\n operationName: params.operationName ?? null,\n});\n\nconst captureRequest = (\n initial: YogaInitialContext,\n requests: Ref.Ref<readonly GraphqlTestRequest[]>,\n) => {\n const url = new URL(initial.request.url);\n const captured: GraphqlTestRequest = {\n url: initial.request.url,\n method: initial.request.method,\n path: url.pathname,\n headers: headersFromRequest(initial.request.headers),\n payload: payloadFromParams(initial.params),\n };\n return Effect.runPromise(\n Ref.update(requests, (all) => [...all, captured]).pipe(Effect.as(captured)),\n );\n};\n\nexport const serveGraphqlTestServer = (\n options: GraphqlTestServerOptions,\n): Effect.Effect<\n GraphqlTestServerShape,\n GraphqlTestServerAddressError | GraphqlTestServerHandlerError,\n Scope.Scope\n> =>\n Effect.gen(function* () {\n const requests = yield* Ref.make<readonly GraphqlTestRequest[]>([]);\n const path = options.path ?? \"/graphql\";\n\n const yoga = createYoga<Record<string, never>, GraphqlTestContext>({\n schema: options.schema,\n graphqlEndpoint: path,\n graphiql: false,\n landingPage: false,\n logging: false,\n maskedErrors: false,\n context: (initial) =>\n captureRequest(initial, requests).then((request) => ({\n request,\n })),\n });\n\n const server = yield* serveTestHttpApp((request) =>\n Effect.gen(function* () {\n const webRequest = yield* HttpServerRequest.toWeb(request);\n const response = yield* Effect.promise(() => Promise.resolve(yoga.handle(webRequest, {})));\n return HttpServerResponse.fromWeb(response);\n }).pipe(\n Effect.catch(() =>\n Effect.succeed(\n HttpServerResponse.text(\"GraphQL test server failed\", {\n status: 500,\n contentType: \"text/plain\",\n }),\n ),\n ),\n ),\n ).pipe(\n Effect.mapError((error) =>\n Predicate.isTagged(error, \"TestHttpServerAddressError\")\n ? new GraphqlTestServerAddressError({ address: error.address })\n : new GraphqlTestServerHandlerError({ cause: error.cause }),\n ),\n );\n\n return {\n endpoint: server.url(path),\n schema: options.schema,\n requests: Ref.get(requests),\n clearRequests: Ref.set(requests, []),\n };\n });\n\nexport class GraphqlTestServer extends Context.Service<GraphqlTestServer, GraphqlTestServerShape>()(\n \"@executor-js/plugin-graphql/testing/GraphqlTestServer\",\n) {\n static readonly layer = (options: GraphqlTestServerOptions) =>\n Layer.effect(GraphqlTestServer, serveGraphqlTestServer(options));\n}\n\nconst stringArgument = (\n args: Readonly<Record<string, unknown>>,\n key: string,\n fallback: string,\n): string => {\n const value = args[key];\n return typeof value === \"string\" ? value : fallback;\n};\n\nexport const makeGreetingGraphqlSchema = (): GraphQLSchema => {\n const Query = new GraphQLObjectType<unknown, GraphqlTestContext>({\n name: \"Query\",\n fields: {\n hello: {\n type: GraphQLString,\n description: \"Say hello\",\n args: {\n name: { type: GraphQLString },\n },\n resolve: (_source, args) => `Hello ${stringArgument(args, \"name\", \"world\")}`,\n },\n },\n });\n\n const Mutation = new GraphQLObjectType<unknown, GraphqlTestContext>({\n name: \"Mutation\",\n fields: {\n setGreeting: {\n type: GraphQLString,\n description: \"Set greeting message\",\n args: {\n message: { type: new GraphQLNonNull(GraphQLString) },\n },\n resolve: (_source, args) => stringArgument(args, \"message\", \"\"),\n },\n },\n });\n\n return new GraphQLSchema({ query: Query, mutation: Mutation });\n};\n\nexport const TestLayers = {\n greeting: () => GraphqlTestServer.layer({ schema: makeGreetingGraphqlSchema() }),\n};\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,OAEL;AACP,SAAS,mBAAmB,0BAA0B;AACtD,SAAS,gBAAgB,mBAAmB,eAAe,qBAAqB;AAChF,SAAS,kBAA+D;AACxE,SAAS,wBAAwB;AAEjC,IAAM,wBAAwB,aAAa,OAAO;AAAA,EAChD,OAAO,aAAa,SAAS,aAAa,MAAM;AAAA,EAChD,WAAW,aAAa,SAAS,aAAa,OAAO,aAAa,QAAQ,aAAa,OAAO,CAAC;AAAA,EAC/F,eAAe,aAAa,SAAS,aAAa,OAAO,aAAa,MAAM,CAAC;AAC/E,CAAC;AA4BD,IAAM,gCAAN,cAA4C,KAAK,YAAY,+BAA+B,EAEzF;AAAC;AAEJ,IAAM,gCAAN,cAA4C,KAAK,YAAY,+BAA+B,EAEzF;AAAC;AAEJ,IAAM,qBAAqB,CAAC,YAC1B,OAAO,YAAY,QAAQ,QAAQ,CAAC;AAEtC,IAAM,oBAAoB,CAAC,YAAkD;AAAA,EAC3E,OAAO,OAAO;AAAA,EACd,WACE,OAAO,OAAO,cAAc,YAAY,OAAO,cAAc,OACzD,OAAO,YACP;AAAA,EACN,eAAe,OAAO,iBAAiB;AACzC;AAEA,IAAM,iBAAiB,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SAAS,eAAe,MAAM,WAAW,EAAE;AAAA,MAChE;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO,IAAI,cAAc,EAAE,OAAO,OAAO,UAAU,SAAS,CAAC;AAC/D;AAEO,IAAM,aAAa;AAAA,EACxB,UAAU,MAAM,kBAAkB,MAAM,EAAE,QAAQ,0BAA0B,EAAE,CAAC;AACjF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@executor-js/plugin-graphql",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.4.20",
|
|
4
4
|
"homepage": "https://github.com/RhysSullivan/executor/tree/main/packages/plugins/graphql",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/RhysSullivan/executor/issues"
|
|
@@ -27,6 +27,18 @@
|
|
|
27
27
|
"types": "./dist/sdk/index.d.ts",
|
|
28
28
|
"default": "./dist/core.js"
|
|
29
29
|
}
|
|
30
|
+
},
|
|
31
|
+
"./client": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/react/plugin-client.d.ts",
|
|
34
|
+
"default": "./dist/client.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./testing": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/testing/index.d.ts",
|
|
40
|
+
"default": "./dist/testing.js"
|
|
41
|
+
}
|
|
30
42
|
}
|
|
31
43
|
},
|
|
32
44
|
"publishConfig": {
|
|
@@ -41,9 +53,11 @@
|
|
|
41
53
|
},
|
|
42
54
|
"dependencies": {
|
|
43
55
|
"@effect/platform-node": "4.0.0-beta.59",
|
|
44
|
-
"@executor-js/config": "
|
|
45
|
-
"@executor-js/sdk": "
|
|
46
|
-
"effect": "4.0.0-beta.59"
|
|
56
|
+
"@executor-js/config": "1.4.20",
|
|
57
|
+
"@executor-js/sdk": "1.4.20",
|
|
58
|
+
"effect": "4.0.0-beta.59",
|
|
59
|
+
"graphql": "^16.12.0",
|
|
60
|
+
"graphql-yoga": "^5.17.0"
|
|
47
61
|
},
|
|
48
62
|
"devDependencies": {
|
|
49
63
|
"@effect/atom-react": "4.0.0-beta.59",
|