-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* with nextjs example * with apollo example * updated readme * Update index.js Unused routes were removed * removed unused routes * ~> fixes
- Loading branch information
Showing
10 changed files
with
167 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,46 @@ | ||
const polka = require('polka'); | ||
const { json } = require('body-parser'); | ||
const { makeExecutableSchema } = require('graphql-tools'); | ||
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express'); | ||
|
||
const { PORT=3000 } = process.env; | ||
|
||
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 }); | ||
|
||
polka() | ||
.use(json()) | ||
.post('/graphql', graphqlExpress(req => ({ | ||
schema | ||
}))) | ||
.get('/graphiql', graphiqlExpress({ | ||
endpointURL: '/graphql' | ||
})) | ||
.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) |
Loading
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,16 @@ | ||
const next = require('next'); | ||
const polka = require('polka'); | ||
|
||
const { PORT=3000, NODE_ENV } = process.env; | ||
|
||
const dev = NODE_ENV !== 'production'; | ||
const app = next({ dev }); | ||
const handle = app.getRequestHandler(); | ||
|
||
app.prepare().then(() => { | ||
polka() | ||
.get('*', handle) | ||
.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": "latest", | ||
"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>About 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,18 @@ | ||
# 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 run build | ||
$ npm start | ||
``` | ||
or | ||
```sh | ||
$ npm install | ||
$ npm run dev | ||
``` | ||
|
||
## Usage | ||
Go to `localhost:3000` after starting the server and get the welcome message |