Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dex4er/js-graphql-codegen-typescript-document-nodes
GraphQL Code Generator plugin for generating TypeScript modules with embedded GraphQL document nodes
https://github.com/dex4er/js-graphql-codegen-typescript-document-nodes
Last synced: 29 days ago
JSON representation
GraphQL Code Generator plugin for generating TypeScript modules with embedded GraphQL document nodes
- Host: GitHub
- URL: https://github.com/dex4er/js-graphql-codegen-typescript-document-nodes
- Owner: dex4er
- License: mit
- Created: 2019-05-19T17:25:37.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-05T20:25:38.000Z (over 5 years ago)
- Last Synced: 2024-10-28T09:02:03.433Z (3 months ago)
- Language: TypeScript
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-codegen-typescript-document-nodes
[![Build Status](https://secure.travis-ci.org/dex4er/js-graphql-codegen-typescript-document-nodes.svg)](http://travis-ci.org/dex4er/js-graphql-codegen-typescript-document-nodes) [![npm](https://img.shields.io/npm/v/graphql-codegen-typescript-document-nodes.svg)](https://www.npmjs.com/package/graphql-codegen-typescript-document-nodes)
This is a plugin for [GraphQL Code
Generator](https://graphql-code-generator.com/) that generates Typescript
source file from GraphQL files.Generated modules export GraphQL as an AST document nodes. Modules use
[`graphql-tag`](https://www.npmjs.com/package/graphql-tag) module.## Requirements
This package requires ES6 with Node >= 8.
## Usage
Configuration in `codegen.yml` file:
```yml
overwrite: true
schema: 'schema/index.json'
documents: 'operations/*.graphql'
generates:
operations/index.ts:
plugins:
- graphql-codegen-typescript-document-nodes
config:
namingConvention: lowerCamelCase
nameSuffix: Query
```With [GitHub GraphQL API v4](https://developer.github.com/v4/) schema and
following GraphQL operation:```graphql
query Viewer {
viewer {
login
name
}
}
```It will generate following Typescript code:
```ts
import { DocumentNode } from 'graphql';
import gql from 'graphql-tag';export const viewerQuery: DocumentNode = gql`
query Viewer {
viewer {
login
name
}
}
`;
```## Configuration
### namingConvention
Allow you to override the naming convention of the output. You can either
override all namings, or specify an object with specific custom naming
convention per output. The format of the converter must be a valid
`module#method`. You can also use "keep" to keep all GraphQL names as-is.
Additionally you can set `transformUnderscore` to `true` if you want to
override the default behaviour, which is to preserve underscores.Override All Names:
```yml
config:
namingConvention: change-case#lowerCase
```Upper-case enum values:
```yml
config:
namingConvention: change-case#pascalCase
```Keep:
```yml
config:
namingConvention: keep
```Transform Underscores:
```yml
config:
namingConvention: change-case#pascalCase
transformUnderscore: true
```### namePrefix
Adds a prefix to GraphQL operation name
### nameSuffix
Adds a suffix to GraphQL operation name
## License
Copyright (c) 2019 Piotr Roszatycki
[MIT](https://opensource.org/licenses/MIT)