Skip to content

Commit 83c5e9d

Browse files
committed
init commit
1 parent ae018bc commit 83c5e9d

File tree

8 files changed

+1802
-0
lines changed

8 files changed

+1802
-0
lines changed

example/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// import the library.. aaaaaaaaah
2+
import { defaultCipherList } from "constants";
3+
import createApp from "../src/index";
4+
5+
// handle fetching pokemons
6+
function pokemons() {
7+
return true;
8+
}
9+
10+
// all the handlers
11+
const handlers = {
12+
mutation: {},
13+
query: {
14+
pokemons,
15+
},
16+
};
17+
18+
function handlerFunc(gqlObject, context) {
19+
//user deets received in header
20+
const userId = context.req.headers.user;
21+
const admin = !!context.req.headers.admin;
22+
23+
const result = gqlObject.queryObjects.every((item) =>
24+
// map the gqlObject to a suitable handler
25+
handlers[gqlObject.type][item.operationName](
26+
item.variables,
27+
item.selectedFields,
28+
{ ...context, user: { _id: userId, admin } }
29+
)
30+
);
31+
32+
return result;
33+
}
34+
35+
const app = createApp(
36+
{ resourceUri: "https://graphql-pokemon2.vercel.app", headers: {} },
37+
handlerFunc
38+
);
39+
40+
app.listen(3000, () => {
41+
console.log("app listening on port 3000");
42+
});

global.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare namespace Express {
2+
export interface Request {
3+
gqlObject?: {
4+
operation?: any;
5+
variables?: any;
6+
};
7+
}
8+
}

0 commit comments

Comments
 (0)