Skip to content

Commit 9bec21b

Browse files
committed
.
0 parents  commit 9bec21b

File tree

11 files changed

+7983
-0
lines changed

11 files changed

+7983
-0
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_size = 2
7+
indent_style = space
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
extends: [
4+
"plugin:react/recommended",
5+
"plugin:@typescript-eslint/recommended",
6+
"prettier/@typescript-eslint",
7+
"plugin:prettier/recommended"
8+
],
9+
parserOptions: {
10+
ecmaVersion: 2018,
11+
sourceType: "module"
12+
}
13+
};

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
coverage/
3+
.DS_Store
4+
npm-debug.log
5+
dist/

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sudo: false
2+
3+
language: node_js
4+
5+
notifications:
6+
email:
7+
on_success: never
8+
on_failure: change
9+
10+
node_js:
11+
- "6"
12+
- stable
13+
14+
after_script:
15+
- npm install coveralls@2
16+
- cat ./coverage/lcov.info | coveralls

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Blake Embrey ([email protected])
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Worker GraphQL
2+
3+
[![NPM version][npm-image]][npm-url]
4+
[![NPM downloads][downloads-image]][downloads-url]
5+
[![Build status][travis-image]][travis-url]
6+
[![Test coverage][coveralls-image]][coveralls-url]
7+
8+
> GraphQL server for worker environments (e.g. Cloudflare Workers).
9+
10+
GraphQL on Workers was inspired by [this blog post](https://blog.cloudflare.com/building-a-graphql-server-on-the-edge-with-cloudflare-workers/), but using Apollo Server has a [massive bundle size](https://github.com/apollographql/apollo-server/issues/1572) or can't bundle due to dependency on `graphql-upload` (a node.js dependency). Using `worker-graphql` resulted in a build of < 50KB.
11+
12+
## Installation
13+
14+
```
15+
npm install @borderlesslabs/worker-graphql --save
16+
```
17+
18+
## Usage
19+
20+
```ts
21+
import { processGraphQL } from "@borderlesslabs/worker-graphql";
22+
import { makeExecutableSchema } from "graphql-tools";
23+
24+
const schema = makeExecutableSchema({
25+
typeDefs: `
26+
type Query {
27+
hello: String
28+
}
29+
`,
30+
resolvers: {
31+
Query: {
32+
hello: () => "Hello world!"
33+
}
34+
}
35+
});
36+
37+
// Wrap `processGraphQL` with CORS support.
38+
const handler = async (req: Request) => {
39+
if (req.method.toUpperCase() === "OPTIONS") {
40+
return new Response(null, {
41+
status: 204,
42+
headers: {
43+
"Access-Control-Allow-Methods": "GET,POST",
44+
"Access-Control-Allow-Headers":
45+
req.headers.get("Access-Control-Request-Headers") || "Content-Type",
46+
"Access-Control-Allow-Origin": "*"
47+
}
48+
});
49+
}
50+
51+
const res = await processGraphQL(req, { schema });
52+
res.headers.set("Access-Control-Allow-Origin", "*");
53+
return res;
54+
};
55+
56+
addEventListener("fetch", event => {
57+
event.respondWith(handler(event.request));
58+
});
59+
```
60+
61+
## License
62+
63+
MIT
64+
65+
[npm-image]: https://img.shields.io/npm/v/borderlesslabs/worker-graphql.svg?style=flat
66+
[npm-url]: https://npmjs.org/package/borderlesslabs/worker-graphql
67+
[downloads-image]: https://img.shields.io/npm/dm/borderlesslabs/worker-graphql.svg?style=flat
68+
[downloads-url]: https://npmjs.org/package/borderlesslabs/worker-graphql
69+
[travis-image]: https://img.shields.io/travis/borderlesslabs/worker-graphql.svg?style=flat
70+
[travis-url]: https://travis-ci.org/borderlesslabs/worker-graphql
71+
[coveralls-image]: https://img.shields.io/coveralls/borderlesslabs/worker-graphql.svg?style=flat
72+
[coveralls-url]: https://coveralls.io/r/borderlesslabs/worker-graphql?branch=master

0 commit comments

Comments
 (0)