open-index/open-npm huggingface dataset:
npm package: @semyenov/effect-graphql
Description: Build type-safe GraphQL schemas with Effect and Effect Schema. Type-safe resolvers, Effect integration, and batched loaders for relation fields.
Latest version: 0.1.2

# @semyenov/effect-graphql

Build type-safe GraphQL schemas with Effect and Effect Schema. Type-safe resolvers, Effect integration, and batched loaders for relation fields.

## Install

```bash
bun add @semyenov/effect-graphql effect graphql
```

## Quickstart

```ts
import { Effect, Schema } from "effect";
import { createGraphApi } from "@semyenov/effect-graphql";

const draft = createGraphApi({ scope: "quickstart", serviceName: "quickstart-api" });
const AuthorBase = draft.object("Author", { id: Schema.String, name: Schema.String });
const QueryBase = draft.object("Query", {});

const objectMap = { Author: AuthorBase, Query: QueryBase } as const;
const builder = draft.withBuilder({ createContext: () => ({}), objectMap });

const Query = builder.contextual(QueryBase, (b) => ({
  author: b.field({
    type: builder.ref("Author"),
    args: Schema.Struct({ id: Schema.String }),
    resolve: (_src, args) => ({ id: args.id, name: "Alice" }),
  }),
  authorEffect: b.effect({
    type: builder.ref("Author"),
    args: Schema.Struct({ id: Schema.String }),
    resolve: (_src, args) => Effect.succeed({ id: args.id, name: "Effect User" }),
  }),
}));

const api = builder.defineRoots({ query: Query });
const schema = api.toSchema();
```

To wire this into an HTTP server, see [Server handlers](docs/server.md). For Effect resolvers, pass `runtimeProvider` to `api.toSchema()`. For loader-backed relation fields with batching and caching, use `builder.defineLoader` (accepts either a `batch` or a `resolver` function) and see [Resolvers — Loader-backed fields](docs/resolvers.md#loader-backed-relation-and-computed-fields).

## Documentation

- [Documentation home](docs/README.md)
- [Quickstart](docs/quickstart.md)
- [Core concepts](docs/concepts.md)
- [Schema definition](docs/schema.md)
- [Resolvers](docs/resolvers.md)
- [Server handlers](docs/server.md)
- [Errors and error policy](docs/errors.md)
- [Observability](docs/observability.md)
- [Configuration](docs/config.md)
- [Examples](docs/examples.md)
- [API reference](docs/api.md)
- [FAQ](docs/faq.md)

## Examples

See `docs/examples.md` for a consolidated guide to the examples.

## Development

```bash
bun install
bun run test:all
bun run check
```