forked from apollographql/apollo-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example application which uses
apollo-server-hapi
. (apollograph…
…ql#2) Much in the same way as this repository has an `apollo-server-express` example, this brings an example which uses hapi.
- Loading branch information
Showing
12 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
*.swp | ||
|
||
pids | ||
logs | ||
results | ||
tmp | ||
|
||
# Build | ||
public/css/main.css | ||
|
||
# Coverage reports | ||
coverage | ||
|
||
# API keys and secrets | ||
.env | ||
|
||
# Dependency directory | ||
node_modules | ||
bower_components | ||
|
||
# Editors | ||
.idea | ||
*.iml | ||
|
||
# OS metadata | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Ignore built ts files | ||
dist/**/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
{ | ||
"language": "node_js", | ||
"node_js": "8", | ||
"services": [ | ||
"mongodb" | ||
], | ||
"script": [ | ||
"npm run build", | ||
"npm run test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"recommendations": [ | ||
"apollographql.vscode-apollo" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible Node.js debug attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "attach", | ||
"name": "Attach by Process ID", | ||
"processId": "${command:PickProcess}", | ||
"protocol": "inspector" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"search.exclude": { | ||
"**/node_modules": true, | ||
"**/bower_components": true, | ||
"**/dist": true, | ||
"**/coverge": true | ||
}, | ||
"typescript.referencesCodeLens.enabled": true, | ||
"cSpell.words": [ | ||
"csrf", | ||
"definitelytyped", | ||
"promisified" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "npm", | ||
"script": "build", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
globals: { | ||
'ts-jest': { | ||
tsConfigFile: 'tsconfig.json' | ||
} | ||
}, | ||
moduleFileExtensions: [ | ||
'ts', | ||
'js' | ||
], | ||
transform: { | ||
'^.+\\.(ts|tsx)$': './node_modules/ts-jest/preprocessor.js' | ||
}, | ||
testMatch: [ | ||
'**/test/**/*.test.(ts|js)' | ||
], | ||
testEnvironment: 'node' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "basic-typescript-hapi", | ||
"version": "0.1.0", | ||
"private": true, | ||
"description": "Apollo Server TypeScript", | ||
"author": "Meteor Development Group, Inc.", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "npm run build && npm run watch-debug", | ||
"build": "npm run build-ts", | ||
"serve": "node dist/server.js", | ||
"watch-node": "nodemon dist/server.js", | ||
"watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"cyan.bold,green.bold\" \"npm run watch-ts\" \"npm run watch-node\"", | ||
"test": "jest --forceExit --coverage --verbose", | ||
"watch-test": "npm run test -- --watchAll", | ||
"build-ts": "tsc", | ||
"watch-ts": "tsc -w", | ||
"debug": "npm run build && npm run watch-debug", | ||
"serve-debug": "nodemon --inspect ./dist/server.js -w ../../packages/\\*/\\*\\*/ --ignore 'src/' -w .", | ||
"watch-debug": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"cyan.bold,green.bold\" \"npm run watch-ts\" \"npm run serve-debug\"" | ||
}, | ||
"peerDependencies": { | ||
"apollo-server-hapi": "*", | ||
"graphql": "*" | ||
}, | ||
"dependencies": { | ||
"hapi": "17.x" | ||
}, | ||
"devDependencies": { | ||
"@types/hapi": "17.x", | ||
"@types/graphql": "^14.0.3", | ||
"@types/jest": "^22.1.3", | ||
"@types/node": "^9.4.6", | ||
"concurrently": "^3.5.1", | ||
"jest": "^22.0.4", | ||
"nodemon": "^1.18.8", | ||
"ts-jest": "^22.0.4", | ||
"ts-node": "^5.0.0", | ||
"typescript": "^3.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { ApolloServer, gql } from 'apollo-server-hapi'; | ||
import Hapi from 'hapi'; | ||
|
||
// This is a (sample) collection of books we'll be able to query | ||
// the GraphQL server for. A more complete example might fetch | ||
// from an existing data source like a REST API or database. | ||
const books = [ | ||
{ | ||
title: "Harry Potter and the Chamber of Secrets", | ||
author: "J.K. Rowling" | ||
}, | ||
{ | ||
title: "Jurassic Park", | ||
author: "Michael Crichton" | ||
} | ||
]; | ||
|
||
// 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 "Book" type can be used in other type declarations. | ||
type Book { | ||
title: String | ||
author: String | ||
} | ||
# The "Query" type is the root of all GraphQL queries. | ||
# (A "Mutation" type will be covered later on.) | ||
type Query { | ||
books: [Book] | ||
} | ||
`; | ||
|
||
// Resolvers define the technique for fetching the types in the | ||
// schema. We'll retrieve books from the "books" array above. | ||
const resolvers = { | ||
Query: { | ||
books: () => books, | ||
} | ||
}; | ||
|
||
const server = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
}); | ||
|
||
const app = new Hapi.Server({ | ||
host: 'localhost', | ||
port: 4000, | ||
}); | ||
|
||
server.applyMiddleware({ | ||
app, | ||
}); | ||
|
||
// Start the server | ||
const start = async function() { | ||
try { | ||
await app.start(); | ||
} | ||
catch (err) { | ||
console.log(err); | ||
process.exit(1); | ||
} | ||
|
||
console.log(`🚀 Server ready at ${app.info.uri}${server.graphqlPath}`); | ||
}; | ||
|
||
start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"target": "es6", | ||
"noImplicitAny": true, | ||
"lib": ["es2017", "esnext.asynciterable"], | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"outDir": "dist", | ||
"baseUrl": ".", | ||
"paths": { | ||
"*": [ | ||
"node_modules/*", | ||
"src/types/*" | ||
] | ||
} | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters