1.5.1 • Published 13 days ago
@powerhousedao/scalars v1.5.1
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:
Create a New Scalar File:
- Navigate to the
src/scalars
directory. - Create a new file for your scalar, e.g.,
MyScalar.ts
.
- Navigate to the
Define the Scalar:
- Implement the scalar using the
GraphQLScalarType
fromgraphql
library or custom logic. - Ensure you export this 4 objects from your new Scalar file:
typedef
: This is the gql type definitionscalar MyScalar
schema
: The zod schema validation for your new scalarconfig
: 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);
- Implement the scalar using the
Update
src/scalars/index.ts
:You can auto generate/update this files using the command:
npx nx generate scalar-generator:new-scalar
- Create a new namespace import for your scalar file
- Include your scalar alias into the exported object
- Update the resolvers object and include your scalar
- 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 ];
Write Tests:
- Add tests for your new scalar to ensure it works as expected.
- Place your tests in the
tests
directory.
Update Documentation:
- Update this README with information about the new scalar.
- Provide examples and usage instructions.
1.1.0-canary.19
13 days ago
1.1.0-canary.18
14 days ago
1.1.0-canary.17
15 days ago
1.1.0-canary.16
15 days ago
1.5.1
15 days ago
1.1.0-canary.13
17 days ago
1.1.0-canary.12
17 days ago
1.1.0-canary.15
16 days ago
1.1.0-canary.14
16 days ago
1.5.0
19 days ago
1.4.0
22 days ago
1.3.0
22 days ago
1.1.0-canary.8
19 days ago
1.1.0-canary.7
22 days ago
1.1.0-canary.9
18 days ago
1.1.0-canary.11
18 days ago
1.1.0-canary.10
18 days ago
1.1.0-canary.6
23 days ago
1.1.0-canary.5
23 days ago
1.1.0-canary.4
24 days ago
1.2.0
25 days ago
1.1.0-canary.3
1 month ago
1.1.0
1 month ago
1.1.0-canary.1
1 month ago
1.0.0
1 month ago