An example of a NestJS application that uses GraphQL with TypeORM.
$ npm install
mv .env.example .env
mv .env.example .env.test
- Create a databases (for development and testing)
- Update POSTGRES_URL
# watch mode
$ npm run start:dev
$ npm run test:e2e
- Using code first approach to define GraphQL schema
- Reduce duplicated code and define everything at one place
- One mutation / query per file
- Field resolvers between entities
Open http://localhost:3000/graphql
query {
recipes(skip: 10, limit: 10) {
id
title
user {
email
}
}
}
query {
users(skip: 2, limit: 2) {
id
email
recipes {
title
}
}
}
mutation {
createUser(createUserInput: {
email: "[email protected]",
name: "Brian Nguyen"
}) {
id
name
email
createdAt
updatedAt
}
}
mutation {
createRecipe(createRecipeInput: {
title: "Rep 01",
ingredients: ["4", "5", "6"],
description: "Wow! The second one",
userId: "<<TAKE_USER_ID_FROM_PREV_STEP>>"
}) {
id
title
createdAt
updatedAt
description
}
}