Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zaiste/graphism

Quickly create GraphQL servers in Deno & Deno Deploy
https://github.com/zaiste/graphism

deno graphql graphql-server javascript typescript

Last synced: 4 months ago
JSON representation

Quickly create GraphQL servers in Deno & Deno Deploy

Awesome Lists containing this project

README

        

# Graphism

*Graphism* is a library for creating GraphQL servers in Deno & Deno Deploy.

- compatible with GraphQL.js 16.6.0
- out of the box GraphiQL
- support for GraphQL JIT

```tsx
import { serve } from 'wren';
import { GET } from 'wren/route.ts';
import * as Response from 'wren/response.ts';
import { GraphQL } from 'graphism';
import SchemaBuilder from 'pothos';

const builder = new SchemaBuilder({});

builder.queryType({
fields: (t) => ({
hello: t.string({
args: {
name: t.arg.string(),
},
resolve: (_parent, { name }) => `Hello, ${name || 'World'}`,
}),
}),
});

const schema = builder.toSchema();

const routes = [
GET('/', () => Response.OK('Graphism')),
GraphQL("/graphql", schema)
];

serve(routes, { port: 3000 });
```

## Getting Started

### Generate a Wren project

```sh
deno run -A -r https://wren.deno.dev my-graphql-server
```

### Add Graphism & (optionally) Pothos

In `import_map.json` add `graphql`, `graphism` and `pothos` as dependencies:

```json
{
"imports": {
// ...
"graphql": "https://esm.sh/[email protected]",
"graphism": "https://deno.land/x/[email protected]/mod.ts",
"pothos": "https://esm.sh/@pothos/[email protected]"
}
}
```

### Build the GraphQL Schema

```tsx
const builder = new SchemaBuilder({});

builder.queryType({
fields: (t) => ({
hello: t.string({
args: {
name: t.arg.string(),
},
resolve: (_parent, { name }) => `Hello, ${name || 'World'}`,
}),
}),
});

const schema = builder.toSchema();
```

### Add the GraphQL route

```tsx
const routes = [
GET('/', () => Response.OK('Graphism')),
GraphQL("/graphql", schema)
];

serve(routes, { port: 3000 });
```

### Start the server

```
deno task start
```