done 1
This commit is contained in:
parent
5bed3a9850
commit
debca3352b
14
package.json
14
package.json
|
@ -1,20 +1,24 @@
|
||||||
{
|
{
|
||||||
"name": "food-graphql-server",
|
"name": "food-graphql-server",
|
||||||
|
"type": "module",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "The GraphQL server to reserve food.",
|
"description": "The GraphQL server to reserve food.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon src/index.js"
|
"start": "tsc-watch --onsuccess \"node ./src/index.js\""
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"apollo-server": "^2.3.1",
|
"apollo-server": "^2.19.2",
|
||||||
"graphql": "^14.1.1",
|
"class-validator": "^0.13.1",
|
||||||
|
"graphql": "^15.5.0",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"type-graphql": "^1.1.1",
|
||||||
"uuid": "^3.3.2"
|
"uuid": "^3.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^1.18.9"
|
"tsc-watch": "^4.2.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
# -----------------------------------------------
|
||||||
|
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
|
||||||
|
# !!! DO NOT MODIFY THIS FILE BY YOURSELF !!!
|
||||||
|
# -----------------------------------------------
|
||||||
|
|
||||||
|
type Query {
|
||||||
|
"""Get all the stores """
|
||||||
|
stores: [Store!]!
|
||||||
|
}
|
||||||
|
|
||||||
|
type Store {
|
||||||
|
id: ID!
|
||||||
|
|
||||||
|
"""The name of the store"""
|
||||||
|
name: String!
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
const uuid = require('uuid');
|
import * as uuid from 'uuid';
|
||||||
|
|
||||||
const stores = [
|
const stores = [
|
||||||
{
|
{
|
||||||
id: 'cc406ed9-fc02-4185-b073-8c12b61b5c79'
|
id: 'cc406ed9-fc02-4185-b073-8c12b61b5c79',
|
||||||
name: 'Den Olijfboom',
|
name: 'Den Olijfboom',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
27
src/index.js
27
src/index.js
|
@ -1,4 +1,10 @@
|
||||||
const { ApolloServer, gql } = require('apollo-server');
|
|
||||||
|
import "reflect-metadata";
|
||||||
|
import { buildSchema } from "type-graphql";
|
||||||
|
|
||||||
|
import * as path from "path";
|
||||||
|
import { ApolloServer, gql } from "apollo-server";
|
||||||
|
import { StoreResolver } from './resolvers.js';
|
||||||
|
|
||||||
// ⚽️ Goal
|
// ⚽️ Goal
|
||||||
// --------
|
// --------
|
||||||
|
@ -19,23 +25,18 @@ const { ApolloServer, gql } = require('apollo-server');
|
||||||
// 4) Create a resolver function that returns the list of stores.
|
// 4) Create a resolver function that returns the list of stores.
|
||||||
// 5) Try out the GraphQL query in the GraphQL Playground (🚀 http://localhost:4000/)
|
// 5) Try out the GraphQL query in the GraphQL Playground (🚀 http://localhost:4000/)
|
||||||
|
|
||||||
// Type definitions define the "shape" of your data and specify
|
|
||||||
// which ways the data can be fetched from the GraphQL server.
|
|
||||||
const typeDefs = gql`
|
|
||||||
type Query {
|
|
||||||
test: String
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
// Resolvers define the technique for fetching the types in the
|
|
||||||
// schema.
|
// create the schema using TypeGraphQL, pass the resolver
|
||||||
const resolvers = {
|
const schema = await buildSchema({
|
||||||
};
|
resolvers: [StoreResolver],
|
||||||
|
emitSchemaFile: path.resolve(".", "schema.gql"),
|
||||||
|
});
|
||||||
|
|
||||||
// In the most basic sense, the ApolloServer can be started
|
// In the most basic sense, the ApolloServer can be started
|
||||||
// by passing type definitions (typeDefs) and the resolvers
|
// by passing type definitions (typeDefs) and the resolvers
|
||||||
// responsible for fetching the data for those types.
|
// responsible for fetching the data for those types.
|
||||||
const server = new ApolloServer({ typeDefs, resolvers });
|
const server = new ApolloServer({ schema });
|
||||||
|
|
||||||
// This `listen` method launches a web-server. Existing apps
|
// This `listen` method launches a web-server. Existing apps
|
||||||
// can utilize middleware options.
|
// can utilize middleware options.
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||||
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||||
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||||
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||||
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||||
|
};
|
||||||
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||||
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||||
|
};
|
||||||
|
import "reflect-metadata";
|
||||||
|
import { Resolver, Query } from "type-graphql";
|
||||||
|
import { Store } from "./typeDefs.js";
|
||||||
|
import { getStores } from "./data.js";
|
||||||
|
let StoreResolver = class StoreResolver {
|
||||||
|
constructor() {
|
||||||
|
this.storeCollection = getStores();
|
||||||
|
}
|
||||||
|
async stores() {
|
||||||
|
return await this.storeCollection;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
__decorate([
|
||||||
|
Query(returns => [Store], { description: "Get all the stores " }),
|
||||||
|
__metadata("design:type", Function),
|
||||||
|
__metadata("design:paramtypes", []),
|
||||||
|
__metadata("design:returntype", Promise)
|
||||||
|
], StoreResolver.prototype, "stores", null);
|
||||||
|
StoreResolver = __decorate([
|
||||||
|
Resolver()
|
||||||
|
], StoreResolver);
|
||||||
|
export { StoreResolver };
|
|
@ -0,0 +1,14 @@
|
||||||
|
import "reflect-metadata";
|
||||||
|
import { Resolver, Query } from "type-graphql";
|
||||||
|
import { Store } from "./typeDefs.js";
|
||||||
|
import { getStores } from "./data.js";
|
||||||
|
|
||||||
|
@Resolver()
|
||||||
|
export class StoreResolver {
|
||||||
|
private storeCollection: Store[] = getStores();
|
||||||
|
|
||||||
|
@Query(returns => [Store], { description: "Get all the stores " })
|
||||||
|
async stores(): Promise<Store[]> {
|
||||||
|
return await this.storeCollection;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Type definitions define the "shape" of your data and specify
|
||||||
|
// which ways the data can be fetched from the GraphQL server.
|
||||||
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||||
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||||
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||||
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||||
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||||
|
};
|
||||||
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||||
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||||
|
};
|
||||||
|
import "reflect-metadata";
|
||||||
|
import { ObjectType, Field, ID } from "type-graphql";
|
||||||
|
let Store = class Store {
|
||||||
|
};
|
||||||
|
__decorate([
|
||||||
|
Field(() => ID),
|
||||||
|
__metadata("design:type", String)
|
||||||
|
], Store.prototype, "id", void 0);
|
||||||
|
__decorate([
|
||||||
|
Field(() => String, { description: "The name of the store" }),
|
||||||
|
__metadata("design:type", String)
|
||||||
|
], Store.prototype, "name", void 0);
|
||||||
|
Store = __decorate([
|
||||||
|
ObjectType()
|
||||||
|
], Store);
|
||||||
|
export { Store };
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Type definitions define the "shape" of your data and specify
|
||||||
|
// which ways the data can be fetched from the GraphQL server.
|
||||||
|
|
||||||
|
import "reflect-metadata";
|
||||||
|
import { ObjectType, Field, ID } from "type-graphql";
|
||||||
|
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
export class Store {
|
||||||
|
@Field(() => ID)
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Field(() => String, { description: "The name of the store" })
|
||||||
|
name: string;
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2018",
|
||||||
|
"module": "esnext",
|
||||||
|
"lib": [
|
||||||
|
"es2018",
|
||||||
|
"esnext.asynciterable"
|
||||||
|
],
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"emitDecoratorMetadata": true
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue