feat: minimal graphql server
This commit is contained in:
parent
6543a729f3
commit
4da6e08448
15
codegen.yml
Normal file
15
codegen.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
schema:
|
||||||
|
- src/graphql/build-schema.js
|
||||||
|
# This should be updated to match your client files
|
||||||
|
# documents: 'client/**/!(*.d).{ts,tsx}'
|
||||||
|
generates:
|
||||||
|
# This will take your schema and print an SDL schema.
|
||||||
|
schema.graphql:
|
||||||
|
plugins:
|
||||||
|
- schema-ast
|
||||||
|
# This will contain the generated apollo hooks and schema types needed to make type-safe queries with the apollo client
|
||||||
|
# __generated__/operations.ts:
|
||||||
|
# plugins:
|
||||||
|
# - typescript
|
||||||
|
# - typescript-operations
|
||||||
|
# - typescript-react-apollo
|
7171
package-lock.json
generated
7171
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -27,6 +27,8 @@
|
||||||
"dbshell": ". .env && psql $DIGITALOCEAN_POSTGRES"
|
"dbshell": ". .env && psql $DIGITALOCEAN_POSTGRES"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@graphql-yoga/node": "^2.1.0",
|
||||||
|
"@pothos/core": "^3.5.1",
|
||||||
"@prisma/client": "^3.11.1",
|
"@prisma/client": "^3.11.1",
|
||||||
"@tailwindcss/forms": "^0.4.0",
|
"@tailwindcss/forms": "^0.4.0",
|
||||||
"@tailwindcss/typography": "^0.5.1",
|
"@tailwindcss/typography": "^0.5.1",
|
||||||
|
@ -84,6 +86,10 @@
|
||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@graphql-codegen/cli": "^2.6.2",
|
||||||
|
"@graphql-codegen/schema-ast": "^2.4.1",
|
||||||
|
"@graphql-codegen/typescript": "^2.4.8",
|
||||||
|
"@graphql-codegen/typescript-operations": "^2.3.5",
|
||||||
"@netlify/plugin-nextjs": "^4.2.4",
|
"@netlify/plugin-nextjs": "^4.2.4",
|
||||||
"@svgr/cli": "^6.2.1",
|
"@svgr/cli": "^6.2.1",
|
||||||
"@types/pg": "^8.6.5",
|
"@types/pg": "^8.6.5",
|
||||||
|
|
11
schema.graphql
Normal file
11
schema.graphql
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
type Query {
|
||||||
|
frontpage: [Question!]!
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
Forecast question.
|
||||||
|
"""
|
||||||
|
type Question {
|
||||||
|
id: String!
|
||||||
|
title: String!
|
||||||
|
}
|
3
src/graphql/build-schema.js
Normal file
3
src/graphql/build-schema.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
require("ts-node").register({});
|
||||||
|
|
||||||
|
module.exports = require("./schema.ts");
|
25
src/graphql/schema.ts
Normal file
25
src/graphql/schema.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
import SchemaBuilder from "@pothos/core";
|
||||||
|
|
||||||
|
import { getFrontpage } from "../backend/frontpage";
|
||||||
|
import { Question } from "../backend/platforms";
|
||||||
|
|
||||||
|
const builder = new SchemaBuilder({});
|
||||||
|
|
||||||
|
const QuestionObj = builder.objectRef<Question>("Question").implement({
|
||||||
|
description: "Forecast question.",
|
||||||
|
fields: (t) => ({
|
||||||
|
id: t.exposeString("id", {}),
|
||||||
|
title: t.exposeString("title", {}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.queryField("frontpage", (t) =>
|
||||||
|
t.field({
|
||||||
|
type: [QuestionObj],
|
||||||
|
resolve: async (parent) => {
|
||||||
|
return await getFrontpage();
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
export const schema = builder.toSchema({});
|
13
src/pages/api/graphql.ts
Normal file
13
src/pages/api/graphql.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { NextApiRequest, NextApiResponse } from "next";
|
||||||
|
|
||||||
|
// apollo-server-micro is problematic since v3, see https://github.com/apollographql/apollo-server/issues/5547, so we use graphql-yoga instead
|
||||||
|
import { createServer } from "@graphql-yoga/node";
|
||||||
|
|
||||||
|
import { schema } from "../../graphql/schema";
|
||||||
|
|
||||||
|
const server = createServer<{
|
||||||
|
req: NextApiRequest;
|
||||||
|
res: NextApiResponse;
|
||||||
|
}>({ schema });
|
||||||
|
|
||||||
|
export default server;
|
Loading…
Reference in New Issue
Block a user