@voxpelli/graphql-utils
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

@voxpelli/graphql-utils

My personal helpers and types for GraphQL

npm version npm downloads neostandard javascript style Module type: ESM Types in JS Follow @voxpelli@mastodon.social

Helpers

  • oneToManyLoader()
  • oneToOneLoader()

Loader helper types

  • OneToManyLoader
  • OneToOneLoader
  • generatePaginatedResponse()
  • paginatedLoader()
  • paginationArgsToSql()

Pagination helper types

  • PageInfo
  • PaginatedLoader
  • PaginationArgs
  • PaginationResponse

Types

  • Loaders
  • Schema
  • CustomContext
  • LoaderWithReturn
  • CustomResolver
  • Shallowing

GraphQL Codegen

These helpers are used with something like this config for https://the-guild.dev/graphql/codegen:

schema: './lib/graphql/schema.graphql'
# documents:
#   - './lib/queries/**/*.{graphql,js}'
#   - './views/**/*.{graphql,js}'
extensions:
  languageService:
    useSchemaFileDefinitions: true
  codegen:
    overwrite: true
    emitLegacyCommonJSImports: false
    config:
      exportFragmentSpreadSubTypes: true
      skipTypename: true
      avoidOptionals: true
      contextType: '@voxpelli/graphql-utils#CustomContext'
      customResolverFn: '@voxpelli/graphql-utils#CustomResolver'
      enumsAsTypes: true
      immutableTypes: true
      noSchemaStitching: true
      wrapFieldDefinitions: false
      resolverTypeWrapperSignature: T
      useTypeImports: true
      # TODO: What is this?
      showUnusedMappers: true
      scalars:
        DateTime: Date
        EmailAddress: string
        JSONObject: JsonObject
        NonEmptyString: string
        UUID: string
    generates:
      lib/graphql/schema.d.ts:
        plugins:
          - add:
              content: '// Automatically generated, do not change!'
          - add:
              content: "import type { JsonObject } from 'type-fest';"
          - typescript
          - typescript-resolvers
      lib/graphql/:
        preset: near-operation-file
        presetConfig:
          extension: -generated.d.ts
          baseTypesPath: schema.js
        plugins:
          - add:
              content: '// Automatically generated, do not change!'
          - typescript-operations:
              inlineFragmentTypes: 'combine'

Readme

Keywords

none

Package Sidebar

Install

npm i @voxpelli/graphql-utils

Weekly Downloads

10

Version

0.3.1

License

MIT

Unpacked Size

31.2 kB

Total Files

20

Last publish

Collaborators

  • voxpelli