-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Test and example updates: - Use fake-tag for GraphQL template literals due to prettier/prettier#4360. - Use express instead of Koa packages. - Use express-graphql instead of Apollo packages. - Example updates: - Stop using esm due to graphql/express-graphql#425. - Enabled GraphiQL and added a link to it on the homepage.
- Loading branch information
1 parent
9988685
commit 63fb310
Showing
17 changed files
with
210 additions
and
219 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
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
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
const express = require('express') | ||
const graphqlHTTP = require('express-graphql') | ||
const { buildSchema } = require('graphql') | ||
const gql = require('fake-tag') | ||
const next = require('next') | ||
|
||
const schema = buildSchema(gql` | ||
type Query { | ||
timer(timerId: ID!): Timer! | ||
timers: [Timer]! | ||
exampleError: Boolean | ||
} | ||
type Mutation { | ||
createTimer: Timer! | ||
} | ||
type Timer { | ||
id: ID! | ||
milliseconds: Int! | ||
} | ||
`) | ||
|
||
const timers = {} | ||
|
||
class Timer { | ||
constructor() { | ||
this.startDate = new Date() | ||
this.id = this.startDate.getTime() | ||
} | ||
|
||
milliseconds() { | ||
return new Date() - this.startDate | ||
} | ||
} | ||
|
||
const rootValue = { | ||
createTimer() { | ||
const timer = new Timer() | ||
return (timers[timer.id] = timer) | ||
}, | ||
timer: ({ timerId }) => timers[timerId], | ||
timers: () => Object.values(timers), | ||
exampleError() { | ||
throw new Error( | ||
'This example error was thrown in the “exampleError” query resolver.' | ||
) | ||
} | ||
} | ||
|
||
const nextApp = next({ dev: process.env.NODE_ENV === 'development' }) | ||
const nextRequestHandler = nextApp.getRequestHandler() | ||
|
||
nextApp.prepare().then(() => | ||
express() | ||
.use('/graphql', graphqlHTTP({ schema, rootValue, graphiql: true })) | ||
.get('*', nextRequestHandler) | ||
.listen(process.env.PORT, error => { | ||
if (error) throw error | ||
// eslint-disable-next-line no-console | ||
console.info( | ||
`Serving localhost:${process.env.PORT} for ${process.env.NODE_ENV}.` | ||
) | ||
}) | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.