Getting Started GraphQL Endpoint With deno !1!1!1!

Barnando Akbarto
4 min readMay 30, 2020

Deno is a brand new competitor for web development server, especially for node js.

When the deno came out, JAVASCRIPT devs that whose already use node js almost lost their hope about the FUTURE of the greatest javascript runtime node.js,

Deno + GraphQL = ❤
love the logo — it’s cute ❤

deno came out with so many features that node js can’t have, I’m not sure what is that I just say it hehe :D.

but you can see more here :

this is a video link btw :v

Ok not get toooooooo longggggg , let’s get into the simple way to used deno

Before we started, you need to install deno runtime to your machine, and you can go to this link https://deno.land/ and try to install them, depends on what machine that you used.

Now I assume that you’ve been already installed deno on your machine, so let get start it.

Check deno if it installed, just type

deno --version
when I start to write this article, I used version 1.0, and it need an update to the latest version 😄

it just like that, if you’re curious you can go to the CLI, it has pretty similar to node.js, again because it is JAVASCRIPT runtime and same author Ryan Dahl

Ok, go to the next step :D

Before continues to start creating the GraphQL server, let’s first install denon module, what is denon?

denon it just like nodemon in deno, almost same I think :D

but I need to update my deno to the lattes version

Make sure you are using deno version ^1.0.1 to install this executable. You can upgrade running (deno upgrade).

SET UP GRAPHQL SERVER

deno + graphql = ❤

GraphQL is a language that enables you to provide a complete and understandable description of the data in your API. Furthermore, it gives clients the power to ask for exactly what they need and nothing more. The project’s website can be found at http://graphql.org/.

Let’s start it.

First, open your text editor, I’m using Visual Studio Code / vscode because it compatible with Typescript, and everyone’s used,

if you use vscode too, I recommend you to install one extension that compatible with deno,

Click on Extension Tabs > Search for deno

And then here we goooooo!!!!

create a new folder that contains this project, and make some file structure that looks like this

that simple pattern that I used to create a simple server based on GraphQL

you can follow my instruction or you can build your own, open “server.js” file and copy or write this code below

and run it with deno in your terminal/cmd

deno run --allow-net server.ts

It starts the server on port 3000 by default.but you can change it

go to http://localhost:8080 to see your server is running.

now go to utils > DB.ts, and copy this code

“./utils/DB.ts” — for Connecting MongoDB with deno

I use MongoDB in this project, but you can use whatever you comfortable with,
oh I forget to mention that I used .env in this silly project, np just copy this code and paste on .env file

.env

now we need to create models interface for the database itself,

“./app/models/Contacts.model.ts”

ok, now time to implement our database models to GraphQL server,

if you don’t understand what this code below means for, no problem I got the same issue as you read this :D ,
JUST READ THE DOC !!!

“./app/schemas/Contacts.schema.ts” — define the schema for graphql

and after we define the scheme, we need to provide a resolvers
What are resolvers is? ok fine go to this link
https://www.apollographql.com/docs/graphql-tools/resolvers/

“./app/resolvers/Contacts.resolvers.ts” resolvers === controllers

and last but not least, we must edit file “server.ts” to connect with OAK server with graphql that we’ve been made before

you can read some other in this link below,

https://github.com/aaronwlee/Oak-GraphQL

here the code

and check your graphql endpoint and try it run or not just type

denon run --allow-net --allow-plugin --unstable --allow-read --allow-write server.ts

here some example

add one
findAll

and that it, I don’t know what ineed to tell again, I apologize if my article are pretty bad, clap if you like this article, thanks for your time.

--

--