fresh start protocol
When you need to make adjustments to your datamodel.graphql database, run the following:
- stop all running containers
docker stop (docker ps -a -q)
- remove all container builds
docker container prune
- remove any volumes associated with previous containers
docker volumen prune
- rebuild fresh containers and volumes
docker-compose up
- use datamodel.graphql to create prisma schema
prisma deploy
- grab autogenerated schema and update the autogen file
graphql get-schema --project database
docker-compose
Current working docker-compose file describes and launches (4) containers on
$ docker-compose up -d
- graphql server (aka the middleman between the client and the prisma service)
- prisma service
- mysql database
- redis
Gotcha's w/ Docker-Compose
http://prisma:4466" NOT 'http://localhost:4466'. This is because of the config we name the prisma service "prisma" on line 11 of the docker-compose file.
when defining the db constant in the index.js, the endpoint needs to point to "const db = new Prisma({
typeDefs: 'src/generated/prisma.graphql',
endpoint: "http://prisma:4466",
debug: true,
secret: "mysecret123",
})
To remove old deployment; limited free tier cleanup
now rm itm-adv-server --safe --yes
Should run get-schema manually as it's not doing it automatically
make sure to be at root directory before running
graphql get-schema --project database
Remember when deploying to ziet now, need to flag .env
now --public --dotenv=.env
Process for adding a new type
Update the following files:
- src/schema.graphql: update type Query and type Mutation with whatever is appropriate for the added type. For example, offers need to be both created by users and retrieved, thus they need:
type Query {
offer(id: ID!): Offer
}
type Mutation {
createOffer(title: String!, text: String!): Offer!
deleteOffer(id: ID!): Offer!
}
-
src/resolvers/Mutation: Need to add a mutations file with the needed functionality (i.e. post, update, delete). See "offer.js".
-
src/resolvers/index: Need to collect all mutations for export as follows:
const { Query } = require('./Query')
const { Subscription } = require('./Subscription')
const { auth } = require('./Mutation/auth')
const { post } = require('./Mutation/post')
const { offer } = require('./Mutation/offer')
const { AuthPayload } = require('./AuthPayload')
module.exports = {
Query,
Mutation: {
...auth,
...post,
...offer,
},
Subscription,
AuthPayload,
}
- src/resolvers/Query.js: Add to Query object:
offer(parent, { id }, ctx, info) {
return ctx.db.query.post({ where: { id }, info })
}
- src/database/datamodel.graphql: Must add offer type here to tell Prisma to make room for it in the database and create the relations
type Offer {
id: ID! @unique
createdAt: DateTime!
updatedAt: DateTime!
title: String!
text: String!
author: User!
}
- Finally when this is all done, from the root, run:
prisma deploy
This should update the backend with new defs and relations src/generated/prisma.graphql should auto-update as a result.
"Borrowing" Queries from prisma.graphql
- in src/generated/prisma.graphql, find Query you want (should have been autogenerated here the last time you ran prisma deploy)
- Copy/paste query into src/schema.graphql. Be sure to import the necessary accompanying types on the query arguments.
- in src/resolvers/Query.js:
const { forwardTo } = require('prisma-binding')
const Query = {
offers: forwardTo("db"),
feed(parent, args, ctx, info) {
return ctx.db.query.posts({ where: { isPublished: true } }, info)
},
...
...
}
EVERYTHING BELOW THIS LINE IS FROM THE README THAT CAME WITH THE BOILERPLATE CODE
Boilerplate for an Advanced GraphQL Server
Features
- Scalable GraphQL server: The server uses
graphql-yoga
which is based on Apollo Server & Express - GraphQL database: Includes GraphQL database binding to Prisma (running on MySQL)
- Authentication: Signup and login workflows are ready to use for your users
- Tooling: Out-of-the-box support for GraphQL Playground & query performance tracing
- Extensible: Simple and flexible data model β easy to adjust and extend
- No configuration overhead: Preconfigured
graphql-config
setup - Realtime updates: Support for GraphQL subscriptions
For a fully-fledged GraphQL & Node.js tutorial, visit How to GraphQL. You can more learn about the idea behind GraphQL boilerplates here.
Requirements
You need to have the GraphQL CLI installed to bootstrap your GraphQL server using graphql create
:
npm install -g graphql-cli
Getting started
# 1. Bootstrap GraphQL server in directory `my-app`, based on `node-advanced` boilerplate
graphql create my-app --boilerplate node-advanced
# 2. When prompted, deploy the Prisma service to a _public cluster_
# 3. Navigate to the new project
cd my-app
# 4. Start server (runs on http://localhost:4000) and open GraphQL Playground
yarn dev
Documentation
Commands
yarn start
starts GraphQL server onhttp://localhost:4000
yarn dev
starts GraphQL server onhttp://localhost:4000
and opens GraphQL Playgroundyarn playground
opens the GraphQL Playground for theprojects
from.graphqlconfig.yml
yarn prisma <subcommand>
gives access to local version of Prisma CLI (e.g.yarn prisma deploy
)
Note: We recommend that you're using
yarn dev
during development as it will give you access to the GraphQL API or your server (defined by the application schema) as well as to the Prisma API directly (defined by the Prisma database schema). If you're starting the server withyarn start
, you'll only be able to access the API of the application schema.
Project structure
File name | Description |
---|---|
βββ .env |
Defines environment variables |
βββ .graphqlconfig.yml |
Configuration file based on graphql-config (e.g. used by GraphQL Playground). |
βββ database (directory) |
Contains all files that are related to the Prisma database service |
βββ prisma.yml |
The root configuration file for your Prisma database service (docs) |
βββ datamodel.graphql |
Defines your data model (written in GraphQL SDL) |
βββ src (directory) |
Contains the source files for your GraphQL server |
βββ index.js |
The entry point for your GraphQL server |
βββ schema.graphql |
The application schema defining the API exposed to client applications |
βββ resolvers (directory) |
Contains the implementation of the resolvers for the application schema |
βββ generated (directory) |
Contains generated files |
βββ prisma.grapghql |
The Prisma database schema defining the Prisma GraphQL API |
Contributing
The GraphQL boilerplates are maintained by the GraphQL community, with official support from the Apollo & Graphcool teams.
Your feedback is very helpful, please share your opinion and thoughts! If you have any questions or want to contribute yourself, join the #graphql-boilerplate
channel on our Slack.