1.5.1 • Published 2 months ago

@powerhousedao/scalars v1.5.1

Weekly downloads
-
License
AGPL-3.0-only
Repository
-
Last release
2 months ago

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)
    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:

    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
    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.
1.1.0-canary.19

2 months ago

1.1.0-canary.18

2 months ago

1.1.0-canary.17

2 months ago

1.1.0-canary.16

2 months ago

1.5.1

2 months ago

1.1.0-canary.13

2 months ago

1.1.0-canary.12

2 months ago

1.1.0-canary.15

2 months ago

1.1.0-canary.14

2 months ago

1.5.0

2 months ago

1.4.0

2 months ago

1.3.0

2 months ago

1.1.0-canary.8

2 months ago

1.1.0-canary.7

2 months ago

1.1.0-canary.9

2 months ago

1.1.0-canary.11

2 months ago

1.1.0-canary.10

2 months ago

1.1.0-canary.6

2 months ago

1.1.0-canary.5

2 months ago

1.1.0-canary.4

2 months ago

1.2.0

2 months ago

1.1.0-canary.3

2 months ago

1.1.0

2 months ago

1.1.0-canary.1

2 months ago

1.0.0

2 months ago