diff --git a/gql commands b/gql commands new file mode 100644 index 0000000..dbc6e56 --- /dev/null +++ b/gql commands @@ -0,0 +1,60 @@ + { + stores{ + id, + name, + city, + number, + postalCode, + street, + products{description,name,price} + } +} + +mutation{ + createStore( + input:{ + name: "asdf", + city: "asdf", + number:2, + postalCode: "hallohallo", + street: "asdf" + } + ) { + id, + name, + city, + number, + postalCode, + street + } +} + +query getStore($storeId: String!, $withProducts: Boolean!){ + store (id:$storeId){ + id, + name, + city, + number, + postalCode, + street, + products @include(if: $withProducts) {id,description,name,price} + } +} +var {"storeId": "5f2919aa-333a-4745-8166-3002ab30de0e","withProducts":true} + +mutation($productId:String!){ + createReservation( + input:{ + reservationProducts: + [ + { + productId:$productId, + quantity:2 + } + ] + } + ) { + id,date,reservationProducts{product{name,description,price},quantity} + } +} +var {"productId":"5bb3fbcc-7ec2-44fe-a04b-a0251cecf1e6"} \ No newline at end of file diff --git a/package.json b/package.json index f273480..988d746 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "graphql": "^15.5.0", "reflect-metadata": "^0.1.13", "type-graphql": "^1.1.1", + "typescript": "^4.1.3", "uuid": "^3.3.2", "yup": "^0.32.8" }, diff --git a/schema.gql b/schema.gql index ddcdc74..fcf2815 100644 --- a/schema.gql +++ b/schema.gql @@ -10,61 +10,61 @@ scalar DateTime type Mutation { """Create a new reservation""" - createReservation(input: ReservationInput!): Reservation! + createReservation(input: ReservationInput): Reservation """Create a new store""" - createStore(input: StoreInput!): Store! + createStore(input: StoreInput): Store } type Product { - description: String! - id: String! - name: String! - price: Float! + description: String + id: String + name: String + price: Float } type Query { """Get a specific store""" - store(id: String!): Store! + store(id: String): Store """Get all the stores""" - stores: [Store!]! + stores: [Store] } type Reservation { - date: DateTime! - id: String! - reservationProducts: [ReservationProduct!]! + date: DateTime + id: String + reservationProducts: [ReservationProduct] } input ReservationInput { - reservationProducts: [ReservationProductInput!]! + reservationProducts: [ReservationProductInput] } type ReservationProduct { - product: Product! - quantity: Int! + product: Product + quantity: Int } input ReservationProductInput { - productId: String! - quantity: Int! + productId: String + quantity: Int } type Store { - city: String! - id: String! - name: String! - number: Int! - postalCode: String! - products: [Product!]! - street: String! + city: String + id: String + name: String + number: Int + postalCode: String + products: [Product] + street: String } input StoreInput { - city: String! - name: String! - number: Int! - postalCode: String! - street: String! + city: String + name: String + number: Int + postalCode: String + street: String } diff --git a/src/index.js b/src/index.js index 618e524..aa20715 100644 --- a/src/index.js +++ b/src/index.js @@ -30,7 +30,7 @@ import { StoreResolver, ReservationResolver } from './resolvers.js'; // create the schema using TypeGraphQL, pass the resolver const schema = await buildSchema({ resolvers: [StoreResolver, ReservationResolver], - //nullableByDefault: true, + nullableByDefault: true, emitSchemaFile: path.resolve(".", "schema.gql"), });