graphql-nexus / nexus

Code-First, Type-Safe, GraphQL Schema Construction
https://nexusjs.org
MIT License
3.4k stars 275 forks source link

Refactor type builder api helpers as a plugin #641

Open jasonkuhrt opened 3 years ago

jasonkuhrt commented 3 years ago

Currently the core has the following builtin:

t.string
t.boolean
t.int
t.float
t.id
t.list
t.nonNull //<-- soon
t.nullable //<-- soon

I am curious if we can re-implement all this as a plugin, bundled with nexus package and turned on by default. Since it wouldn't be possible to "uninstall" the plugin this would be a refactor from the pointer of view of users.

In core the only thing left should be t.field (and of course the few misc others like t.modify and t.implements.

jasonkuhrt commented 3 years ago

WDTY @tgriesser @Weakky ?

tgriesser commented 3 years ago

Technically I think it'd be possible... it might be a neat exercise just to try and see what it'd look like.

From a DX standpoint, it'd be a rough out of the box experience unless we special case'd this plugin because you don't get the plugin extension typings until the first run of the schema... in which case I don't know if it makes sense to make this change vs keeping what we already have.

There's also a bit of indirection when things are implemented as a plugin, and the surface area of these fields are pretty lean. Not sure.

jasonkuhrt commented 3 years ago

because you don't get the plugin extension typings until the first run of the schema... in which case I don't know if it makes sense to make this change vs keeping what we already have.

Ah, great point.

One way of seeing this is that it puts pressure on finding ways to make this smoother for users in general, so that all plugins and the typegen system generally benefits.

But in practice its a pretty hard problem to solve in a way that "Just Works". It'll be stuff like "VSCode plugin" and "post install hook" and "cli" and ... never a single silver bullet.

tgriesser commented 3 years ago

But in practice its a pretty hard problem to solve in a way that "Just Works". It'll be stuff like "VSCode plugin" and "post install hook" and "cli" and ... never a single silver bullet.

Yeah. Have a few ideas here that might be good to put together before 1.0 - specifically around simplifying the initial generation.

Also, a VSCode plugin that watches the generated schema file for file changes to refresh the typescript types is the biggest DX thing I'm missing at the moment... it's such a big pain point - @jasonkuhrt anything you've seen or used to improve that?

jasonkuhrt commented 3 years ago

Also, a VSCode plugin that watches the generated schema file for file changes to refresh the typescript types is the biggest DX thing I'm missing at the moment... it's such a big pain point - @jasonkuhrt anything you've seen or used to improve that?

Do you mean having VSCode reflect updated typings when a new typegen file is generated?

For this we found on framework that generating into node_modules/@types/typegen-nexus/index.d.ts worked practically flawlessly in the sense of VSCode picking up changes there reliably.

The part I'm not quite sure what you mean is:

a VSCode plugin that watches the generated schema file for file changes to refresh the typescript types