-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
|
||
pnpm-lock.yaml | ||
yarn.lock | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "express", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"express": "^4.19.2", | ||
"express-graphql": "^0.12.0", | ||
"graphql": "^15.9.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const { buildSchema } = require('graphql') | ||
const express = require('express') | ||
const { graphqlHTTP } = require('express-graphql') | ||
|
||
// 使用 GraphQL schema language 构建一个 schema | ||
const schema = buildSchema(` | ||
type Query { | ||
hello: String | ||
} | ||
`) | ||
|
||
// 根节点为每个 API 入口端点提供一个 resolver 函数 | ||
const resolver = { | ||
hello: () => { | ||
return 'Hello world!' | ||
}, | ||
} | ||
|
||
const app = express() | ||
|
||
app.use( | ||
'/graphql', | ||
graphqlHTTP({ | ||
schema: schema, | ||
rootValue: resolver, | ||
graphiql: true, | ||
}), | ||
) | ||
|
||
app.listen(4000) | ||
|
||
console.log('Running a GraphQL API server at http://localhost:4000/graphql') |