# @powerhousedao/scalars

> This repository contains custom GraphQL scalars used by Powerhouse.

Latest version **2.0.1** (published 2025-05-08) · AGPL-3.0-only license · 0 weekly downloads

## Install

```sh
npm install @powerhousedao/scalars
pnpm add @powerhousedao/scalars
yarn add @powerhousedao/scalars
bun add @powerhousedao/scalars
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2025-05-08 |
| First published | 2024-10-11 |
| Weekly downloads | 0 |
| License | AGPL-3.0-only |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 401.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | acaldas.powerhouse, memo.dev, ryanwolhuter, callme-t, froid |

## Links

- npm: https://www.npmjs.com/package/@powerhousedao/scalars
- npm.io page: https://npm.io/package/@powerhousedao/scalars

## Recent versions

- 2.0.1 (latest) — 2025-05-08
- 1.33.1-dev.11 (dev) — 2025-05-15
- 1.30.1-canary.59 (canary) — 2025-05-14
- 1.33.1-staging.5 (staging) — 2025-05-13
- 1.30.1-canary.58 — 2025-05-13
- 1.30.1-canary.57 — 2025-05-13
- 1.33.1-dev.10 — 2025-05-09
- 1.30.1-canary.56 — 2025-05-08
- 1.33.1-dev.9 — 2025-05-08
- 2.0.0 — 2025-05-07
- 1.33.1-dev.8 — 2025-05-07
- 1.30.1-canary.55 — 2025-05-07
- 1.30.1-canary.54 — 2025-05-06
- 1.30.1-canary.53 — 2025-05-06
- 1.30.1-canary.52 — 2025-05-06
- … 417 more at https://npm.io/package/@powerhousedao/scalars/versions

## README

# Powerhouse Scalars

This repository contains custom GraphQL scalars used by Powerhouse.

## Adding New Scalars

To add a new scalar to this repository, follow these steps:

1. **Create a New Scalar File**:

    - Navigate to the `src/scalars` directory.
    - Create a new file for your scalar, e.g., `MyScalar.ts`.

2. **Define the Scalar**:

    - Implement the scalar using the `GraphQLScalarType` from `graphql` library or custom logic.
    - Ensure you export this 4 objects from your new Scalar file:
        - `typedef`: This is the gql type definition `scalar MyScalar`
        - `schema`: The zod schema validation for your new scalar
        - `config`: The graphql config for your scalar (`GraphQLScalarTypeConfig` type)
        - `scalar`: The graphql scalar object (`GraphQLScalarTypeConfig` type)

    ```typescript
    import { GraphQLScalarType, GraphQLScalarTypeConfig, Kind } from 'graphql';
    import { z } from 'zod';

    export const typedef = 'scalar MyScalar';
    export const schema = z.string();
    export const config: GraphQLScalarTypeConfig<any, any> = {
        name: 'MyScalar',
        description: 'Description of MyScalar',
        serialize(value: any): any {
            // Implement serialization logic
        },
        parseValue(value: any): any {
            // Implement parsing logic
        },
        parseLiteral(ast: any): any {
            if (ast.kind === Kind.STRING) {
                // Implement literal parsing logic
            }
            return null;
        },
    };

    export const scalar = new GraphQLScalarType(config);
    ```

3. **Update `src/scalars/index.ts`**:

    You can auto generate/update this files using the command:
    ```bash
    npx nx generate scalar-generator:new-scalar
    ```

    1. Create a new namespace import for your scalar file
    2. Include your scalar alias into the exported object
    3. Update the resolvers object and include your scalar
    4. Update the typeDefs array and inlcude your scalar typedef

    ```typescript
    import * as EmailAddress from './EmailAddress';
    import * as MyScalar from './MyScalar'; // 1.- namespace import

    export {
        EmailAddress,
        MyScalar, // 2.- Update exported object
    };

    export const resolvers = {
        EmailAddress: EmailAddress.scalar,
        MyScalar: MyScalar.scalar, // 3.- Update resolvers object
    };

    export const typeDefs = [
        EmailAddress.typedef,
        MyScalar.typedef, // 4.- Update typeDefs object
    ];
    ```

4. **Write Tests**:

    - Add tests for your new scalar to ensure it works as expected.
    - Place your tests in the `tests` directory.

5. **Update Documentation**:
    - Update this README with information about the new scalar.
    - Provide examples and usage instructions.

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