-
Notifications
You must be signed in to change notification settings - Fork 173
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
Added support for graphql-code-generator, and some other improvements #129
Conversation
replace graphqlhub with fakerql api replace ui example with todo app added `graphql-tag/loader` to webpack build
This is awesome work, thanks @dotansimha! Give me a couple of days to play with this PR locally and get familiar with the new features, then I'll get this merged. On first glance, looks great! |
I love this! @prisma makes a similar tool called graphqlgen. It's only 10 days old but the prisma ecosystem has a lot of backing and seems promising. Probably not mature enough to integrate now though. |
@bmschwartz , The
@bmschwartz , as a side note, even just for the backend, I believe our template is much better than what |
Thanks @dotansimha, I'll read into both projects further. I remembered reading about Didn't realize you were the author of that project. Awesome! |
@leebenson, now the code-generator has a Webpack plugin (dotansimha/graphql-code-generator#739, thanks to @kamilkisiela), I'll update this PR to use once we'll release a new version :) |
I updated the PR to the latest stable version of the codegen. It improves the performance, and much easier to read the output of it :) |
@dotansimha - my apologies in the delay in getting back to you on this PR. Will try and get some time in the coming week to review. |
Hi @leebenson :) Any update? |
Sorry for my slow response to this. When I run install the latest packages and run
I think it'd be nicer for ReactQL if we had a more graceful error message, since it's likely Watchman won't be installed by default on a target machine. Is that something that can be handled in ReactQL-land code? Or does it need to be handled upstream in your own package? |
Some additional issues I came across...
(I've pasted it as a screenshot to give the full impression of what a user would first see.) I'd love to see this updated with a friendlier message about what happened; it's not apparent exactly what went wrong. (In this case, it was a
Those steps are quite opinionated and brittle. I think it would be preferable to have GraphQL building as a separate NPM script/build step, so that: a) Running b) If the GraphQL schema changes, there's a simple/explicit way to rebuild schema (which should, ideally, be then picked up by the Webpack watcher and automatically restart the dev server.) This would make it easir to then just open another Terminal window and rebuild the schema at will. @dotansimha, if you have the free time/interest to tackle the above, I'd love to get this included. I can see this lib being of a great use in most every project... it's just the build/start-up flow that needs refining, IMO. |
In v4.2, I added graphql-code-generator along with demo schema and React plugins. The schema can be rebuilt with:
I think this is a great midway point between generating types, and having a full dev experience that re-gens on file save. With VSCode/other IDE plugins, the interop is pretty straightforward and it eliminates the need for Watchman or couple the generator too tightly to user-land code that may not require it. @dotansimha, I want to thank you for your hard work on this, and for putting together an excellent package. I'd highly recommend anyone reading give it a shot - it really cuts down both on TS type generation, and manually wiring up Apollo HOCs. Love it! |
Thank you @leebenson ! sounds great! |
Hi @leebenson ! I'm using reactql for some of our projects, and it's awesome!
In this PR I added some nice features and extensions, that makes it easier to write client-side GraphQL apps with TypeScript.
I know this PR is big, but let me know what do you think, and I can separate it to smaller pieces if it will be easier to get it merged.
The changes in this PR are:
Added support for
.graphql
filesAdded
graphql-tag/loader
to Webpack configuration, this way it's possible now to import from.graphql
files directly, without wrapping it with.ts
files.Client-side schema declatation
Instead of using TypeScript schema for local-state, we can write the GraphQL client-side (local state) schema as regular GraphQL schema in
.graphql
file.Added
graphql-code-generator
I updated the boilerplate to use
graphql-code-generator
, and now it's generating typings, components and more.The idea is to use type-safety, and use GraphQL-first approach.
I'm using the codegen to generate typings for both local and remote schema.
The codegen is running in watch mode during development, and single-time during build.
Also, during the generation, the codegen uses the schema and the client-side operations and fragments, and validates it, so you'll get the errors now during compilation, instead of during the app runtime:
Schema typings
Now that schema typings are available, for both remote schema and local schema, we can remove
IRoot
andIState
declarations, and generate them directly from the declared schema.React Wrapper components
Now it also generates React components that wraps
<Query>
and<Mutation >
fromreact-apollo
. And we are getting a full type-safe queries and mutations, with IDE auto-complete.It's also generates typings for the selection set of queries and mutations, and you get auto-complete for the fields you requested on the query:
.graphql
modules declarationI'm using
graphql-codegen-typescript-react-apollo-template
template of the codegen, to generate typings for.graphql
files import, this way we can import from.graphql
files, and also have a type-safe on those imports (import { myQuery } from './my-query.graphql'
).Changed remote GraphQL schema
I replaced
graphqlhub
withfakerql
becausegraphqlhub
uses a very old implementation of GraphQL server, and no longer maintained.We can't use the codegen with this version, and it the basic idea is to have a query from a remote source, Todo should do the trick.
Also,
fakerql
has a very useful schema, including useful types such asTodo
,User
,Product
,Post
and more.