I've been working on a project lately, which has node.js + express + typescript + Apollo server stack. And while researching on Apollo client, I've stumbled upon TypeScript section. But nothing like that was for server, which leaves me to freedom of choice in this case.
So the question is: are there any best practices on implementing Apollo graphql server with typescript or what should I avoid at least?
I wrote a small library and a CLI for this. It generates TypeScript typings for both server (according to your schema) and client (according to your schema and GraphQL documents). It also generates resolvers signature and very customizable.
You can try it here: https://github.com/dotansimha/graphql-code-generator
The idea behind it was to allow the developer to get the most out of GraphQL and the generated typings, and making it easier to customize the generated output.
I am using a GraphQL CLI. You would install it like so
npm install -g graphql-cli
then generate your GraphQL project with TypeScript support
More information: https://oss.prisma.io/content/graphql-cli/05-Boilerplates.html
I've been using typescript + apollo graphql server for quite some time and started a template which incorporates dotan's graphql-code-generator along with some a defined folder structure and approach which makes everything work together nicely. Focus is to keep it simple, but I continue to add to it as I find good practices and useful libraries.
The github repo is here.
I've been using apollo-server-express with Typescript for some projects and I have a small demo on gitHub with it.
I'm not sure about best practices
, but apollo-server-express
basically it provides a graphqlExpress
and graphiqlExpress
handlers.
Check out the docs about Apollo Server with Express for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With