- graphql-yoga
- mongoose
- ES6+ syntax using babel
- Schemas
- ! means a mandatory variable
# import Test from 'test.graphql'
type Query {
tests: [Test]!
}
type Mutation {
addTest(text: String!): Test
}
const resolvers = {
Query: {
tests: () => {...}
},
Mutation: {
addTest: (_, { id }) => {...}
}
}
import { GraphQLServer } from 'graphql-yoga';
import { importSchema } from 'graphql-import';
const typeDefs = importSchema(path.join(__dirname, 'graphql', 'schema.graphql'));
const server = new GraphQLServer({ typeDefs, resolvers });
server.start(() => console.log('GraphQL server running on localhost:4000'));
Mutation {
addTest(text: "Hello") {
text
}
}
npm install --save-dev @babel/cli @babel/core @babel/node @babel/preset-env nodemon
npm install -g pm2 && npm install --save pm2
{ "presets": ["@babel/preset-env"] }
- package.json
- --copy-files -> build with non-JS files including graphql
"scripts": {
"start": "NODE_ENV=production pm2 start build/app.js -i 0",
"dev": "nodemon --exec babel-node src/app.js",
"build": "babel src --out-dir build --copy-files",
}
import 'dotenv/config'; // import dotenv at the very start