From a0480fb6791f9829fd3396e811c6180e665040be Mon Sep 17 00:00:00 2001 From: Kristof Van Miegem Date: Sat, 26 Jan 2019 14:06:08 +0100 Subject: [PATCH] chore: initial project setup --- .gitignore | 8 ++++++++ README.md | 6 ++++++ package.json | 16 ++++++++++++++++ src/index.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 package.json create mode 100644 src/index.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..112a1ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Package managers +node_modules +npm-debug.log +yarn-error.log +package-lock.json + +# OS +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..8c51e79 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Getting started + +``` +npm i +npm run start +``` \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..75ccb2e --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "food-graphql-server", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "apollo-server": "^2.3.1", + "graphql": "^14.1.1" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..479da44 --- /dev/null +++ b/src/index.js @@ -0,0 +1,46 @@ +const { ApolloServer, gql } = require('apollo-server'); + +const stores = [ + { + name: 'Den Olijfboom', + }, + { + name: 'Pizza Talia' + } +]; + +// Type definitions define the "shape" of your data and specify +// which ways the data can be fetched from the GraphQL server. +const typeDefs = gql` + # Comments in GraphQL are defined with the hash (#) symbol. + + # This "Store" type can be used in other type declarations. + type Store { + name: String + } + + # The "Query" type is the root of all GraphQL queries. + # (A "Mutation" type will be covered later on.) + type Query { + stores: [Store] + } +`; + +// Resolvers define the technique for fetching the types in the +// schema. We'll retrieve books from the "books" array above. +const resolvers = { + Query: { + stores: () => stores, + }, +}; + +// In the most basic sense, the ApolloServer can be started +// by passing type definitions (typeDefs) and the resolvers +// responsible for fetching the data for those types. +const server = new ApolloServer({ typeDefs, resolvers }); + +// This `listen` method launches a web-server. Existing apps +// can utilize middleware options, which we'll discuss later. +server.listen().then(({ url }) => { + console.log(`🚀 Food GraphQL Server ready at ${url}`); +});