Skip to content

Commit 4bb38db

Browse files
committed
Init project
0 parents  commit 4bb38db

File tree

7 files changed

+947
-0
lines changed

7 files changed

+947
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.prettierrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"tabWidth": 2,
3+
"trailingComma": "none",
4+
"printWidth": 80,
5+
"singleQuote": true,
6+
"semi": false,
7+
"arrowParens": "always"
8+
}

README.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<h1 align="center"><strong>Boilerplate for a Basic GraphQL Server</strong></h1>
2+
3+
<br />
4+
5+
![](https://imgur.com/lIi4YrZ.png)
6+
7+
<div align="center"><strong>🚀 Bootstrap your GraphQL server within seconds</strong></div>
8+
<div align="center">Basic starter kit for a flexible GraphQL server for Node.js - based on best practices from the GraphQL community.</div>
9+
10+
## Features
11+
12+
- **Scalable GraphQL server:** The server uses [`apollo-server v2`](https://github.com/apollographql/apollo-server) which is based on new Apollo Server
13+
- **GraphQL database:** Includes GraphQL database binding to [Prisma](https://www.prisma.io) (running on MySQL)
14+
- **Tooling**: Out-of-the-box support for [GraphQL Playground](https://github.com/prisma/graphql-playground) & [query performance tracing](https://github.com/apollographql/apollo-tracing)
15+
- **Extensible**: Simple and flexible [data model](./database/types.graphql) – easy to adjust and extend
16+
- **No configuration overhead**: Preconfigured [`graphql-config`](https://github.com/prisma/graphql-config) setup
17+
18+
For a fully-fledged **GraphQL & Node.js tutorial**, visit [How to GraphQL](https://www.howtographql.com/graphql-js/0-introduction/). You can more learn about the idea behind GraphQL boilerplates [here](https://blog.graph.cool/graphql-boilerplates-graphql-create-how-to-setup-a-graphql-project-6428be2f3a5).
19+
20+
## Requirements
21+
22+
You need to have the [GraphQL CLI](https://github.com/graphql-cli/graphql-cli) installed to bootstrap your GraphQL server using `graphql init`, [Prisma](https://github.com/graphcool/prisma) to deploy and update database use `prisma deploy` and [Yarn](https://yarnpkg.com/lang/en/) to install npm packages:
23+
24+
```sh
25+
npm install -g graphql-cli prisma yarn
26+
```
27+
28+
## Getting started
29+
30+
```sh
31+
# 1. Clone the project
32+
git clone https://github.com/danilobrinu/prisma-apollo-starter.git
33+
34+
# 2. Navigate to the new project
35+
cd prisma-apollo-starter
36+
37+
# 3. Install npm packages
38+
yarn install
39+
40+
# 4. Start server (runs on http://localhost:4000) and open GraphQL Playground
41+
yarn dev
42+
```
43+
44+
> Note: Create new enviroment using example.env and update **`__PRISMA_ENDPOINT__`** if you don't have prisma endpoint run `prisma deploy` and use Demo Server to get prisma endpoint
45+
46+
47+
![](https://imgur.com/hElq68i.png)
48+
49+
## Documentation
50+
51+
### Commands
52+
53+
* `yarn start` starts GraphQL server on http://localhost:4000
54+
* `yarn debug` starts GraphQL server in debug mode on http://localhost:4000
55+
* `yarn playground` opens the GraphQL Playground for the `projects` from [`.graphqlconfig.yml`](./.graphqlconfig.yml)
56+
* `yarn dev` starts GraphQL server on http://localhost:4000 _and_ opens GraphQL Playground
57+
* `prisma <subcommand>` gives access to local version of Prisma CLI (e.g. `prisma deploy`)
58+
59+
> **Note**: We recommend that you're using `yarn dev` during development as it will give you access to the GraphQL API or your server (defined by the [application schema](./src/schema.graphql)) as well as to the Prisma API directly (defined by the [Prisma database schema](./src/generated/prisma.graphql)). If you're starting the server with `yarn start`, you'll only be able to access the API of the application schema.
60+
61+
### Project structure
62+
63+
![](https://imgur.com/95faUsa.png)
64+
65+
| File name               | Description         <br><br>|
66+
| :-- | :-- |
67+
| `├── example.env` | Use this file to configure your enviroment (copy/paste or rename to .env) |
68+
| `├── .graphqlconfig.yml` | Configuration file based on [`graphql-config`](https://github.com/prisma/graphql-config) (e.g. used by GraphQL Playground).|
69+
| `└── database/ ` | _Contains all files that are related to the Prisma database service_ |\
70+
| `  ├── prisma.yml` | The root configuration file for your Prisma database service ([docs](https://www.prisma.io/docs/reference/prisma.yml/overview-and-example-foatho8aip)) |
71+
| `  └── enums.graphql` | Defines your enums for data model (written in [GraphQL SDL](https://blog.graph.cool/graphql-sdl-schema-definition-language-6755bcb9ce51)) |
72+
| `  └── seed.graphql` | Defines your seed data model (written in [GraphQL SDL](https://blog.graph.cool/graphql-sdl-schema-definition-language-6755bcb9ce51)) |
73+
| `  └── types.graphql` | Defines your types for data model (written in [GraphQL SDL](https://blog.graph.cool/graphql-sdl-schema-definition-language-6755bcb9ce51)) |
74+
| `└── src/ ` | _Contains the source files for your GraphQL server_ |
75+
| `  ├── index.js` | The entry point for your GraphQL server |
76+
| `  ├── schema.graphql` | The **application schema** defining the API exposed to client applications |
77+
| `  ├── resolvers/ ` | _Contains the implementation of the resolvers for the application schema_ |
78+
| `  └── generated/ ` | _Contains generated files_ |
79+
| `    └── prisma.grapghql` | The **Prisma database schema** defining the Prisma GraphQL API |
80+
81+
## Contributing
82+
83+
The GraphQL boilerplates are maintained by the GraphQL community, with official support from the [Apollo](https://dev-blog.apollodata.com) & [Graphcool](https://blog.graph.cool/) teams.
84+
85+
Your feedback is **very helpful**, please share your opinion and thoughts! If you have any questions or want to contribute yourself, join the [`#graphql-boilerplate`](https://graphcool.slack.com/messages/graphql-boilerplate) channel on our [Slack](https://graphcool.slack.com/).

index.js

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
const puppeteer = require('puppeteer-core')
2+
const { extract, cleanup } = require('aws-puppeteer-lambda')
3+
4+
exports.handler = async (evt, ctx, cb) => {
5+
// Extract the headless chrome executable and return its path.
6+
// If a previous Lambda invocation has extracted the executable, it will be reused.
7+
const executablePath = await extract()
8+
9+
const browser = await puppeteer.launch({
10+
ignoreHTTPSErrors: true,
11+
args: [
12+
'--disable-dev-shm-usage',
13+
'--disable-gpu',
14+
'--single-process',
15+
'--no-zygote',
16+
'--no-sandbox'
17+
],
18+
executablePath
19+
})
20+
21+
// Use evt.queryStringParameters to get the params from GET
22+
const url = evt.queryStringParameters.url
23+
24+
const done = (result = { success: false, data: null }) =>
25+
cb(null, {
26+
statusCode: 200,
27+
body: JSON.stringify(result),
28+
isBase64Encoded: false
29+
})
30+
31+
const page = await browser.newPage()
32+
33+
// Pass the User-Agent Test.
34+
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36'
35+
await page.setUserAgent(userAgent)
36+
37+
// Pass the Webdriver Test.
38+
await page.evaluateOnNewDocument(() => {
39+
const newProto = navigator.__proto__
40+
delete newProto.webdriver
41+
navigator.__proto__ = newProto
42+
})
43+
44+
// Pass the Chrome Test.
45+
await page.evaluateOnNewDocument(() => {
46+
// We can mock this in as much depth as we need for the test.
47+
window.chrome = {
48+
runtime: {}
49+
}
50+
})
51+
52+
// Pass the Permissions Test.
53+
await page.evaluateOnNewDocument(() => {
54+
const originalQuery = window.navigator.permissions.query
55+
window.navigator.permissions.__proto__.query = (parameters) =>
56+
parameters.name === 'notifications'
57+
? Promise.resolve({ state: Notification.permission })
58+
: originalQuery(parameters)
59+
60+
// Inspired by: https://github.com/ikarienator/phantomjs_hide_and_seek/blob/master/5.spoofFunctionBind.js
61+
const oldCall = Function.prototype.call
62+
function call() {
63+
return oldCall.apply(this, arguments)
64+
}
65+
Function.prototype.call = call
66+
67+
const nativeToStringFunctionString = Error.toString().replace(
68+
/Error/g,
69+
'toString'
70+
)
71+
const oldToString = Function.prototype.toString
72+
73+
function functionToString() {
74+
if (this === window.navigator.permissions.query) {
75+
return 'function query() { [native code] }'
76+
}
77+
if (this === functionToString) {
78+
return nativeToStringFunctionString
79+
}
80+
return oldCall.call(oldToString, this)
81+
}
82+
Function.prototype.toString = functionToString
83+
})
84+
85+
// Pass the Plugins Length Test.
86+
await page.evaluateOnNewDocument(() => {
87+
// Overwrite the `plugins` property to use a custom getter.
88+
Object.defineProperty(navigator, 'plugins', {
89+
// This just needs to have `length > 0` for the current test,
90+
// but we could mock the plugins too if necessary.
91+
get: () => [1, 2, 3, 4, 5]
92+
})
93+
})
94+
95+
// Pass the Languages Test.
96+
await page.evaluateOnNewDocument(() => {
97+
// Overwrite the `plugins` property to use a custom getter.
98+
Object.defineProperty(navigator, 'languages', {
99+
get: () => ['en-US', 'en']
100+
})
101+
})
102+
103+
// Pass the iframe Test
104+
await page.evaluateOnNewDocument(() => {
105+
Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', {
106+
get: function() {
107+
return window
108+
}
109+
})
110+
})
111+
112+
// Pass toString test, though it breaks console.debug() from working
113+
await page.evaluateOnNewDocument(() => {
114+
window.console.debug = () => {
115+
return null
116+
}
117+
})
118+
119+
try {
120+
await page.goto(url);
121+
} catch(e) {
122+
await browser.close();
123+
124+
done()
125+
}
126+
127+
const result = await page.evaluate(() => {
128+
// Put your code here
129+
return { success: true, data: 'Hello AWS Lambda!' }
130+
})
131+
132+
await browser.close()
133+
134+
done(result)
135+
cleanup()
136+
}

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"aws-puppeteer-lambda": "^1.0.2",
4+
"puppeteer-core": "^1.9.0"
5+
}
6+
}

0 commit comments

Comments
 (0)