Initial commit

This commit is contained in:
Joshua Seigler 2020-01-28 23:08:53 -05:00
commit 0bd76ac5dc
8 changed files with 1386 additions and 0 deletions

14
server/app.js Normal file
View 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

File diff suppressed because it is too large Load diff

28
server/package.json Normal file
View 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
View 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
});