# Graphql

Open-Source

Released 2015 from Facebook

# Rest vs. Graphql

## Pizza service

### Rest Service

### Graphql Service

# benefits

## No more Over- and Underfetching

fixed data structures provide to much or not enough data

## Type/Schema System

- Graphql uses an strict Type and Schema
- The Client can be sure about what it get
- aswell as the server

## Growing Community and Integrations

- Good Client side Integrations Angular/React/VueJs and more.
- Server side Integrations in Typescript/Java and more.
- Well working code-generator for client and server
- Alot of well writen Documentation

## Self Documenting

## Faster API Development

## pros/cons

# disadvantages

### more complex

### no file uploading

# Demo

## Basics

- Types
- Querys
- Mutations
- Variables

## Types

                  type Pizza {
                    id: ID!
                    name: String!
                    toppings: [Topping!]!
                  }

                  type Topping {
                    id: ID!
                    name: String!
                  }

## Querys

### Define Querys

                type Query {
                  getPizzaById(pizzaId: ID!): Pizza!
                  getToppingById(toppingId: ID!): Topping!
                  getPizzaByName(pizzaName: ID!): Pizza!
                  getToppingByName(toppingName: ID!): Topping!
                  listPizza: [Pizza]!
                  listTopping: [Topping]!
                }

### Simple Query

                  {
                    listPizza {
                      id
                      name
                    }
                  }

### More Complex Query

                  {
                    getPizzaById(pizzaId: "0") {
                      id
                      name
                      toppings {
                        name
                      }
                    }
                  }

## Mutations

### Define Mutations

                  type Mutation {
                    createPizza(createPizzaDto: ChangePizzaDto): Pizza!
                    updatePizza(pizzaId: ID!, updatedPizzaDto: ChangePizzaDto!): Pizza!
                    createTopping(createToppingDto: ChangeToppingDto): Topping!
                    updateTopping(toppingId: ID!, updatedToppingDto: ChangeToppingDto!): Topping!
                  }

### Mutation

                  mutation {
                    createPizza (createPizzaDto: {
                      name: "My Awesome Pizza"
                      toppingIds: "1"
                    }) {
                      id
                      name
                      toppings {
                        id
                        name
                      }
                    }
                  }

graphql-codegen

apollo-angular