Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Date type by default #61

Open
capaj opened this issue Sep 13, 2018 · 4 comments
Open

support Date type by default #61

capaj opened this issue Sep 13, 2018 · 4 comments

Comments

@capaj
Copy link
Contributor

capaj commented Sep 13, 2018

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
Copy link
Collaborator

pie6k commented Sep 13, 2018

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
Copy link

It's not true 😉
TypeStrong/ts-node#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:
kulshekhar/ts-jest#439

@capaj
Copy link
Contributor Author

capaj commented Sep 13, 2018

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

@capaj
Copy link
Contributor Author

capaj commented Sep 13, 2018

I did make it work in my namespaced fork of typegql: capaj@19a9dd5

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants