-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added examples #48
Merged
Merged
Added examples #48
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b67f186
with nextjs example
jerolan 26b404a
with apollo example
jerolan 813717c
updated readme
jerolan 0f107a4
Update index.js
jerolan cacf3b8
removed unused routes
jerolan 017fe80
merge
jerolan de49d24
~> fixes
lukeed File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,52 @@ | ||
const polka = require('polka') | ||
const bodyParser = require('body-parser') | ||
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express') | ||
const { makeExecutableSchema } = require('graphql-tools') | ||
|
||
const { PORT = 3000 } = process.env | ||
const app = polka() | ||
|
||
const tasks = [ | ||
{ id: 1, name: 'Go to Market', complete: false }, | ||
{ id: 2, name: 'Walk the dog', complete: true }, | ||
{ id: 3, name: 'Take a nap', complete: false } | ||
] | ||
|
||
const typeDefs = ` | ||
type Task { | ||
id: Int! | ||
name: String! | ||
complete: Boolean! | ||
} | ||
|
||
type Query { | ||
tasks: [Task] | ||
task(id: Int!): Task | ||
} | ||
` | ||
|
||
const resolvers = { | ||
Query: { | ||
tasks: () => tasks, | ||
task: (_, args) => tasks.find(o => o.id === args.id) | ||
} | ||
} | ||
|
||
const schema = module.exports = makeExecutableSchema({ | ||
typeDefs, | ||
resolvers | ||
}) | ||
|
||
app.use(bodyParser.json()) | ||
|
||
app.post('/graphql', graphqlExpress(req => ({ | ||
schema | ||
}))) | ||
|
||
app.get('/graphiql', graphiqlExpress({ | ||
endpointURL: '/graphql' | ||
})) | ||
|
||
app.listen(PORT).then(_ => { | ||
console.log(`> Ready on localhost:${PORT}`) | ||
}) |
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 @@ | ||
{ | ||
"scripts": { | ||
"start": "node index" | ||
}, | ||
"dependencies": { | ||
"apollo-server-express": "^1.3.6", | ||
"body-parser": "^1.18.3", | ||
"graphql": "^0.13.2", | ||
"graphql-tools": "^3.0.2", | ||
"polka": "^0.3.4" | ||
} | ||
} |
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,37 @@ | ||
# Example: Apollo Graphql | ||
|
||
Tiny example with [Apollo Graphql](https://www.apollographql.com/) | ||
|
||
It uses the [`Apollo Server`](https://github.com/apollographql/apollo-server) a community-maintained open-source GraphQL server. | ||
|
||
## Setup | ||
```sh | ||
$ npm install | ||
$ npm start | ||
``` | ||
|
||
## Usage | ||
You can use it with any apollo client or with the [Graphiql](https://github.com/graphql/graphiql) in [localhost](http://localhost:3000/graphiql) | ||
|
||
## Available queries | ||
``` | ||
{ | ||
tasks { | ||
id | ||
name | ||
complete | ||
} | ||
} | ||
``` | ||
|
||
``` | ||
{ | ||
task (id: Int!) { | ||
id | ||
name | ||
complete | ||
} | ||
} | ||
``` | ||
|
||
![Screenshot](screenshot.png) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,3 @@ | ||
.next | ||
node_modules | ||
package-lock.json |
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,17 @@ | ||
const polka = require('polka') | ||
const next = require('next') | ||
|
||
const port = parseInt(process.env.PORT, 10) || 3000 | ||
const dev = process.env.NODE_ENV !== 'production' | ||
const app = next({ dev }) | ||
const handle = app.getRequestHandler() | ||
|
||
app.prepare().then(() => { | ||
const server = polka() | ||
|
||
server.get('*', (req, res) => handle(req, res)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can actually be |
||
|
||
server | ||
.listen(port) | ||
.then(() => console.log(`> Ready on http://localhost:${port}`)) | ||
}) |
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,13 @@ | ||
{ | ||
"scripts": { | ||
"dev": "node index.js", | ||
"build": "next build", | ||
"start": "NODE_ENV=production node index.js" | ||
}, | ||
"dependencies": { | ||
"next": "latest", | ||
"polka": "0.2.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's bump this to |
||
"react": "16.2.0", | ||
"react-dom": "16.2.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,11 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
|
||
export default () => ( | ||
<div> | ||
<h1>Home Page</h1> | ||
<Link href='/'> | ||
Link to Home | ||
</Link> | ||
</div> | ||
) |
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,11 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
|
||
export default () => ( | ||
<div> | ||
<h1>Home Page</h1> | ||
<Link href='/about'> | ||
Link to About Page | ||
</Link> | ||
</div> | ||
) |
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,17 @@ | ||
# Example: Next.js | ||
|
||
It uses [`Next.js`](https://github.com/zeit/next.js) a Framework for server-rendered or statically-exported React apps. | ||
|
||
## Setup | ||
```sh | ||
$ npm install | ||
$ npm start | ||
``` | ||
or | ||
```sh | ||
$ npm install | ||
$ npm run dev | ||
``` | ||
|
||
## Usage | ||
Go to localhost:3000 after starting the server and get the welcome message |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's import it as
const { json } = require('body-parser')
then update the usage below too