mirror of
https://github.com/seigler/graphql-playground
synced 2025-07-27 01:26:10 +00:00
Initial commit
This commit is contained in:
commit
0bd76ac5dc
8 changed files with 1386 additions and 0 deletions
14
server/app.js
Normal file
14
server/app.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
const express = require('express');
|
||||
const graphqlHTTP = require('express-graphql');
|
||||
|
||||
const schema = require('./schema/schema');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use('/graphql', graphqlHTTP({
|
||||
schema
|
||||
}));
|
||||
|
||||
app.listen(4000, () => {
|
||||
console.log('Listening on http://localhost:4000');
|
||||
});
|
1272
server/package-lock.json
generated
Normal file
1272
server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
28
server/package.json
Normal file
28
server/package.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "graphql-playground",
|
||||
"version": "1.0.0",
|
||||
"description": "Playing with GraphQL to learn it",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon app",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/seigler/graphql.git"
|
||||
},
|
||||
"author": "Joshua Seigler",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/seigler/graphql/issues"
|
||||
},
|
||||
"homepage": "https://github.com/seigler/graphql#readme",
|
||||
"dependencies": {
|
||||
"express": "^4.17.1",
|
||||
"express-graphql": "^0.9.0",
|
||||
"graphql": "^14.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.2"
|
||||
}
|
||||
}
|
33
server/schema/schema.js
Normal file
33
server/schema/schema.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const graphql = require('graphql');
|
||||
|
||||
const {
|
||||
GraphQLObjectType,
|
||||
GraphQLString,
|
||||
GraphQLSchema
|
||||
} = graphql;
|
||||
|
||||
const BookType = new GraphQLObjectType({
|
||||
name: 'Book',
|
||||
fields: () => ({
|
||||
id: { type: GraphQLString },
|
||||
name: { type: GraphQLString },
|
||||
genre: { type: GraphQLString }
|
||||
})
|
||||
});
|
||||
|
||||
const RootQuery = new GraphQLObjectType({
|
||||
name: 'RootQueryType',
|
||||
fields: {
|
||||
book: {
|
||||
type: BookType,
|
||||
args: { id: { GraphQLString } },
|
||||
resolve (parent, { id }) {
|
||||
// code to retrieve data from db or other source
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = new GraphQLSchema({
|
||||
query: RootQuery
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue