Graphql-code-generator: Add option to output immutable types

Created on 17 Sep 2017  路  10Comments  路  Source: dotansimha/graphql-code-generator

Option to make output typings comply tslint-immutable rules:

  • add to each interface property readonly keyword
  • use ReadonlyArray instead of Array or T[].
enhancement plugins waiting-for-release

Most helpful comment

@BjornMelgaard I'm implementing this right now :)

All 10 comments

Sounds good. Also, it makes sense if you are using apollo-client, because it also return an immutable results.

@BjornMelgaard what do you think about creating a PR for this?

@dotansimha , ok, it seems not so hard to add 2 new templates :smile: , I'll try on weekends.

@BjornMelgaard I think that we should allow to create config file for the generator.
At the moment I added support for gql-gen.json file, but the config there is for the generator code only, but I think we can extend it for generator-specific configuration.
This way the immutable feature will be on the same TS generator, instead of creating a new one.

What do you think?

@dotansimha ok, no new templates, just integrate this functionality in existing typescript-multi-file and typescript-single-file and activate it with something like

{
  "immutable": true/false,
  "flattenTypes": true,
  "primitives": {
    "String": "string",
    "Int": "number",
    "Float": "number",
    "Boolean": "boolean",
    "ID": "string"
  },
  "customHelpers": {
    "myHelper": "./my-helper.js"
  }
}

At the moment I added support for gql-gen.json file, but the config there is for the generator code only, but I think we can extend it for generator-specific configuration.

If I correctly understand you, you just saying that there is no way to access user config option (like "immutable" or "flattenType" above) in handlebars template and you want to add it

@dotansimha hi, how its going?

how can I get 'immutable' property from users config in handlebars template? :smiley:

@BjornMelgaard I'm implementing this right now :)

Seems like the PR above is now merged! Would it be possible to continue work on this issue now?

@jonaskello @srghma implemented in: https://github.com/dotansimha/graphql-code-generator/pull/293 :)

Done in 0.9.0 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mszczepanczyk picture mszczepanczyk  路  3Comments

NickClark picture NickClark  路  3Comments

quolpr picture quolpr  路  3Comments

steebchen picture steebchen  路  3Comments

leebenson picture leebenson  路  3Comments