Skip to content

Commit feb4806

Browse files
committed
Start GraphQL API
1 parent 2bf9d81 commit feb4806

File tree

5 files changed

+95
-7
lines changed

5 files changed

+95
-7
lines changed

api/graphql/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { FABRuntime } from "@fab/core";
2+
import { makeGraphQLHandler } from "@glenstack/cf-workers-graphql";
3+
import { schema } from "./schema/index";
4+
5+
const graphQLHandler = makeGraphQLHandler(schema);
6+
7+
export default function graphql({ Router }: FABRuntime) {
8+
Router.on("/graphql", ({ request }) => graphQLHandler(request));
9+
}

api/graphql/schema/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { makeExecutableSchema } from "@graphql-tools/schema";
2+
import gql from "graphql-tag";
3+
4+
const typeDefs = gql`
5+
type Query {
6+
hello: String
7+
}
8+
`;
9+
10+
const resolvers = {
11+
Query: {
12+
hello: () => "Hello, world!",
13+
},
14+
};
15+
16+
export const schema = makeExecutableSchema({ typeDefs, resolvers });

fab.config.json5

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// For more information, see https://fab.dev/kb/configuration
22
{
33
plugins: {
4-
'@fab/input-static': {
5-
dir: 'build'
4+
"@fab/input-static": {
5+
dir: "build",
66
},
7-
'@fab/plugin-render-html': {
8-
fallback: '/index.html'
7+
"./api/graphql/index.ts": {},
8+
"@fab/plugin-render-html": {
9+
fallback: "/index.html",
910
},
10-
'@fab/plugin-rewire-assets': {}
11+
"@fab/plugin-rewire-assets": {},
1112
// This section defines your build & runtime toolchains. See https://fab.dev/kb/plugins
1213
},
1314
settings: {
@@ -18,13 +19,13 @@
1819
// allowing for many production-specific optimisations. See https://fab.dev/kb/production
1920
// Example setting:
2021
// API_URL: 'https://api.example.com/graphql'
21-
}
22+
},
2223
},
2324
deploy: {
2425
// For manual (command-line) deploys, add configuration here.
2526
// • See https://fab.dev/guides/deploying for more info.
2627
// However, we recommend automatic deploys (triggered by git push)
2728
// using a service such as Linc (https://linc.sh)
2829
// • See https://fab.dev/kb/automatic-deploys for setup instructions.
29-
}
30+
},
3031
}

package-lock.json

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"private": true,
55
"dependencies": {
66
"@fontsource/inter": "4.1.0",
7+
"@glenstack/cf-workers-graphql": "1.0.4",
8+
"@graphql-tools/schema": "6.0.18",
79
"@headlessui/react": "0.2.0",
810
"@testing-library/jest-dom": "5.11.9",
911
"@testing-library/react": "11.2.3",
@@ -13,6 +15,7 @@
1315
"@types/react": "17.0.0",
1416
"@types/react-dom": "17.0.0",
1517
"classnames": "2.2.6",
18+
"graphql-tag": "2.11.0",
1619
"react": "17.0.1",
1720
"react-dom": "17.0.1",
1821
"react-router-dom": "5.2.0",

0 commit comments

Comments
 (0)