Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apollo GraphQL Server + TypeScript

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?

like image 516
naffiq Avatar asked Jun 18 '18 08:06

naffiq


4 Answers

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.

like image 146
Dotan Simha Avatar answered Oct 23 '22 21:10

Dotan Simha


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

enter image description here

More information: https://oss.prisma.io/content/graphql-cli/05-Boilerplates.html

like image 30
AFD Avatar answered Oct 23 '22 22:10

AFD


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.

like image 21
henry74 Avatar answered Oct 23 '22 20:10

henry74


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.

like image 37
Marco Daniel Avatar answered Oct 23 '22 20:10

Marco Daniel