prismake / typegql

Create GraphQL schema with TypeScript classes.
https://prismake.github.io/typegql/
MIT License
424 stars 21 forks source link

support Date type by default #61

Open capaj opened 6 years ago

capaj commented 6 years ago

currently if you want to handle dates correctly for a field, you need to explicitly use a scalar, like this:

  @Field({ type: GraphQLDateTime })
  created_at: Date

since this is very common-it would be great to enable this behavior by default, so you can omit the explicit type:

  @Field()
  created_at: Date
pie6k commented 6 years ago

Sadly - currently typescript reflect api does not recognize dates: http://blog.wolksoftware.com/decorators-metadata-reflection-in-typescript-from-novice-to-expert-part-4

If it's changed - would be great to add such feature

MichalLytek commented 6 years ago

It's not true 😉 https://github.com/TypeStrong/ts-node/issues/511

There's was a bug with TypeScript compiler api that is used programatically like by ts-jest but it's reported to be fixed: https://github.com/kulshekhar/ts-jest/issues/439

capaj commented 6 years ago

awesome @19majkel94! Will take a stab at implementation.

capaj commented 6 years ago

I did make it work in my namespaced fork of typegql: https://github.com/capaj/typegql/commit/19a9dd5444723f1993e4840964eedeeae43904f4

I attempted the same in this repo and it ended up in error while building:

$ ttsc --project ttsconfig.json
/home/capaj/git_projects/graphql-repos/typegql/node_modules/typescript/lib/tsc.js:114358
})(ts || (ts = {}));
^

SyntaxError: Unexpected token }
    at Object.<anonymous> (/home/capaj/git_projects/graphql-repos/typegql/node_modules/ttypescript/lib/tsc.js:26:14)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/capaj/git_projects/graphql-repos/typegql/node_modules/ttypescript/bin/tsc:2:1)
    at Module._compile (module.js:652:30)
error Command failed with exit code 1.

also jest infer test failed as well. Maybe jest is still running some old version of typescript? Not sure.

I can't really open a PR from my fork, because it has those DuplexTypes and some of other changes. So I guess it's up to you @pie6k