npm.io
1.7.0 • Published yesterday

@rafads/plugin-graphql

Licence
MIT
Version
1.7.0
Deps
5
Size
407 kB
Vulns
0
Weekly
0

@rafads/plugin-graphql

Introspect a GraphQL endpoint and expose its queries and mutations as invokable tools on an executor.

Install

bun add @rafads/sdk @rafads/plugin-graphql
# or
npm install @rafads/sdk @rafads/plugin-graphql

Usage

import { createExecutor } from "@rafads/sdk";
import { graphqlPlugin } from "@rafads/plugin-graphql";

const executor = await createExecutor({
  onElicitation: "accept-all",
  plugins: [graphqlPlugin()] as const,
});

// Public endpoint — no auth
await executor.graphql.addIntegration({
  scope: executor.scopes[0]!.id,
  endpoint: "https://graphql.anilist.co",
  namespace: "anilist",
});

const tools = await executor.tools.list();
const result = await executor.tools.invoke("anilist.Media", {
  search: "Frieren",
});

Secret-backed auth

import { createExecutor } from "@rafads/sdk";
import { graphqlPlugin } from "@rafads/plugin-graphql";
import { fileSecretsPlugin } from "@rafads/plugin-file-secrets";

const executor = await createExecutor({
  onElicitation: "accept-all",
  plugins: [fileSecretsPlugin(), graphqlPlugin()] as const,
});

const scope = executor.scopes[0]!.id;

await executor.secrets.set({
  id: "github-token",
  name: "GitHub Token",
  value: "ghp_...",
  scope,
});

await executor.graphql.addIntegration({
  scope,
  endpoint: "https://api.github.com/graphql",
  namespace: "github",
  headers: {
    Authorization: { secretId: "github-token", prefix: "Bearer " },
  },
});

Using with Effect

If you're building on @rafads/sdk/core (the raw Effect entry), import this plugin from its /core subpath instead — it returns the Effect-shaped plugin with Effect.Effect<...>-returning methods rather than promisified wrappers:

import { graphqlPlugin } from "@rafads/plugin-graphql/core";

Status

Pre-1.0. APIs may still change between beta releases. Part of the executor monorepo.

License

MIT