# graphql-codegen-on-operations

> A plugin for [https://the-guild.dev/graphql/codegen](graphql-codegen) to create a signature from your documents which can be validated on the server

Latest version **0.0.1** (published 2023-06-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphql-codegen-on-operations
pnpm add graphql-codegen-on-operations
yarn add graphql-codegen-on-operations
bun add graphql-codegen-on-operations
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2023-06-20 |
| First published | 2023-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | IlijaNL |
| Maintainers | ilijanl |

## Links

- npm: https://www.npmjs.com/package/graphql-codegen-on-operations
- Repository: https://github.com/ilijaNL/graphql-codegen-on-operations
- Homepage: https://github.com/ilijaNL/graphql-codegen-on-operations#readme
- Issues: https://github.com/ilijaNL/graphql-codegen-on-operations/issues
- npm.io page: https://npm.io/package/graphql-codegen-on-operations

## Dependencies (2)

- [@graphql-tools/documents](https://npm.io/package/@graphql-tools/documents.md) ^0.1.0
- [@graphql-codegen/plugin-helpers](https://npm.io/package/@graphql-codegen/plugin-helpers.md) ^4.2.0

## Recent versions

- 0.0.1 (latest) — 2023-06-20

## README

# GraphQL codegen plugin to generate some code/configuration from operations/fragments

A plugin for [https://the-guild.dev/graphql/codegen](graphql-codegen) to create a signature from your documents which can be validated on the server

## Install

Install graphql-code-generator and this plugin

    yarn add -D @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations graphql-codegen-on-operations

## Usage

Create codegen.ts

```ts
import * as dotenv from 'dotenv'; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
dotenv.config();
import type { CodegenConfig } from '@graphql-codegen/cli';
import createSignFn from 'graphql-codegen-on-operations/lib/use/signing';
import createListFn from 'graphql-codegen-on-operations/lib/use/listing';
import { GenerateFn } from 'graphql-codegen-on-operations';
import { print } from 'graphql';

const customGen: GenerateFn = (_schema, { documents }) => {
  return JSON.stringify(documents.map((d) => print(d.node)).join('\n'), null, 2);
};

const config: CodegenConfig = {
  schema: 'http://localhost:3000/api/graphql',
  documents: ['gql/**/*.graphql'],
  generates: {
    './__generated__/gql.ts': {
      plugins: ['typescript', 'typescript-operations', 'typed-document-node'],
    },
    './__generated__/signed-operations.json': {
      plugins: ['graphql-codegen-on-operations'],
      config: {
        gen: createSignFn({
          // should be long and not exposed to public
          secret: process.env.SIGNING_SECRET,
        }),
      },
    },
    './__generated__/list-operations.json': {
      plugins: ['graphql-codegen-on-operations'],
      config: {
        gen: createListFn(),
      },
    },
    './__generated__/custom.json': {
      plugins: ['graphql-codegen-on-operations'],
      config: {
        gen: customGen,
      },
    },
  },
};
export default config;
```

---
_Source: https://npm.io/package/graphql-codegen-on-operations · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
