GraphQLGroup
Groups of GraphQL operations, merged to build a client. Group middleware
runs outside operation middleware. @effect/graphql-generator emits one
group per document file.
Combinators
Merges groups into one. Middleware attached to a source group stays attached to that group's operations; middleware attached to the merged group afterwards runs outside all of it.
Signature
declare function merge<Groups extends readonly Array<Any>>(...groups: Groups): GraphQLGroup<Operations<Groups[number]>>Example Auth on one file, logging on everything
import { Schema } from "effect"import { GraphQL, GraphQLGroup, GraphQLMiddleware } from "effect/graphql"
class Auth extends GraphQLMiddleware.Service<Auth>()("app/Auth") {}class Logging extends GraphQLMiddleware.Service<Logging>()("app/Logging") {}
const Viewer = GraphQL.query("Viewer", { document: "query Viewer{viewer{login}}", result: Schema.Struct({ viewer: Schema.Struct({ login: Schema.String }) })})const Rate = GraphQL.query("Rate", { document: "query Rate{rateLimit{remaining}}", result: Schema.Struct({ rateLimit: Schema.Struct({ remaining: Schema.Int }) })})
const all = GraphQLGroup.merge(GraphQLGroup.make(Viewer).middleware(Auth), GraphQLGroup.make(Rate)) .middleware(Logging)
all.operations.map((op) => op.name) // => ["Viewer", "Rate"]all.middlewares.map((m) => m.key) // => ["app/Logging"]all.operations[0].middlewares.map((m) => m.key) // => ["app/Auth"]Constructors
Builds a group from operations. Operation names must be unique within a group, because they become the client's method names.
Signature
declare function make<Ops extends readonly Array<Any>>(...operations: Ops): GraphQLGroup<Ops[number]>Example
import { Schema } from "effect"import { GraphQL, GraphQLGroup } from "effect/graphql"
const Viewer = GraphQL.query("Viewer", { document: "query Viewer{viewer{login}}", result: Schema.Struct({ viewer: Schema.Struct({ login: Schema.String }) })})
const ViewerGraphQLGroup = GraphQLGroup.make(Viewer)
ViewerGraphQLGroup.operations.map((op) => op.name) // => ["Viewer"]Guards
Since v4.0.0 Source
Tests whether a value is a GraphQLGroup.
Signature
declare function isGraphQLGroup(u: unknown): u is AnyModels
GraphQLGroup
interface Since v4.0.0 Source
A set of operations plus the middleware attached at the group level.
Signature
interface GraphQLGroup<out Ops extends GraphQL.Any> extends Pipeable { readonly "~effect/graphql/GraphQLGroup": "~effect/graphql/GraphQLGroup"; readonly middlewares: readonly Array<AnyService>; readonly operations: readonly Array<Ops>; middleware<M extends AnyService>(middleware: M): GraphQLGroup<AddMiddleware<Ops, M>>;}Utility Types
Any group, with its operations erased.
Signature
type Any = GraphQLGroup<GraphQL.Any>Operations
type Since v4.0.0 Source
Extracts the union of operations in a group.
Signature
type Operations<G> = G extends GraphQLGroup<infer Ops> ? Ops : never