Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vicary committed Mar 11, 2024
1 parent 2cddba0 commit 158320c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
46 changes: 31 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# fresh-graphql

GraphQL development for Deno Fresh.
A simple GraphQL server for Deno Fresh.

## Live Demo

Expand All @@ -17,24 +17,34 @@ GraphQL development for Deno Fresh.

1. [Create a fresh project](https://fresh.deno.dev/docs/getting-started/create-a-project)
or checkout your existing Fresh project.

1. Add the following lines to your `dev.ts`:

```diff
import "https://deno.land/x/dotenv/load.ts";
```diff
import "https://deno.land/x/dotenv/load.ts";

import dev from "$fresh/dev.ts";
+ import { dev as graphql } from "@vicary/fresh-graphql";
import dev from "$fresh/dev.ts";
+import { dev as graphql } from "@vicary/fresh-graphql";

+ await graphql(import.meta.url);
await dev(import.meta.url, "./main.ts");
```
+await graphql(import.meta.url);
await dev(import.meta.url, "./main.ts");
```

1. Include the `graphql/` directory in your deno.json.

```diff
"tasks": {
- "start": "deno run -A --watch=static/,routes/ dev.ts",
+ "start": "deno run -A --watch=static/,routes/,graphql/ dev.ts",
}
```

## Usage

### Entrypoint

Any data handler routes would work, the example below uses `/graphql` as a
convension.
Any data handler routes would work, the example below uses the pathname
`/graphql` as a convension.

```ts
// routes/graphql.ts
Expand Down Expand Up @@ -62,7 +72,7 @@ export const handler = async (req: Request, ctx: FreshContext) => {
### Queries and Mutations

```ts
// ./graphql/Query/joke.ts
// graphql/Query/joke.ts

export const schema = /* GraphQL */ `
extend type Query {
Expand Down Expand Up @@ -105,7 +115,7 @@ export const resolver = {
### Subscriptions

```ts
// ./graphql/Subscription/countdown.ts
// graphql/Subscription/countdown.ts

export const schema = /* GraphQL */ `
extend type Subscription {
Expand All @@ -121,12 +131,18 @@ export const resolver = async function* (_, { from }) {
};
```

### Directives

Supported, documentations coming.

You may read `dev.ts` if you need it now.

### Side notes

1. `@graphql-yoga/common` is chosen for it's simplicity, you may use any GraphQL
servers compatible with `@graphql-tools/schema`.
1. `graphql-yoga` is chosen for it's simplicity, you may use any GraphQL servers
compatible with `@graphql-tools/schema`.
1. `graphql.gen.ts` This is the manifest file generated whenever you make
changes to source codes in the `./graphql` directory.
changes to source codes in the `graphql` directory.

## Sponsorship

Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vicary/fresh-graphql",
"version": "0.1.3",
"version": "0.1.5",
"exports": "./mod.ts",
"lock": false,
"nodeModulesDir": false
Expand Down
2 changes: 1 addition & 1 deletion examples/graphql-yoga/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -",
"manifest": "deno task cli manifest $(pwd)",
"preview": "deno run -A main.ts",
"start": "deno run -A --watch=static/,routes/ dev.ts",
"start": "deno run -A --watch=static/,routes/,graphql/ dev.ts",
"update": "deno run -A -r https://fresh.deno.dev/update ."
}
}

0 comments on commit 158320c

Please sign in to comment.