• v3
  • Integrations
  • Deno

GraphQL Yoga provides you a cross-platform GraphQL Server. So you can easily integrate it into any platform besides Node.js. Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust. We will use graphql-yoga which has an agnostic HTTP handler using Fetch API's Request and Response objects.

Example

Create a deno-yoga.ts file;

import { createYoga, createSchema } from 'npm:graphql-yoga'
 
const yoga = createYoga({
  schema: createSchema({
    typeDefs: /* GraphQL */ `
      type Query {
        hello: String!
      }
    `,
    resolvers: {
      Query: {
        hello: () => 'Hello Deno!',
      },
    },
  }),
})
 
Deno.serve(
  async (req) => {
    const res = await yoga.handleRequest(req)
    return new Response(res.body, res)
  },
  {
    port: 4000,
  },
)

And run it;

deno run --allow-net --allow-env --allow-read --unstable --compat index.ts

You can also check a full example on our GitHub repository here

Last updated on September 20, 2022