This repository has been archived by the owner on Jul 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from prisma/feature/experimental-extensions
[RFR] Add support for express middlewares
- Loading branch information
Showing
20 changed files
with
247 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ dist | |
yalc.lock | ||
yarn.lock | ||
package-lock.json | ||
.idea | ||
.idea | ||
.docz |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,51 @@ | ||
import { Server } from 'http' | ||
import * as path from 'path' | ||
import { ApolloServer, makeSchema, Yoga } from 'yoga' | ||
import { ApolloServer, express, makeSchema, yogaEject } from 'yoga' | ||
import context from './context' | ||
import * as types from './graphql' | ||
|
||
export default { | ||
server: dirname => { | ||
export default yogaEject({ | ||
async server() { | ||
const app = express() | ||
|
||
const schema = makeSchema({ | ||
types, | ||
outputs: { | ||
schema: path.join(dirname, './schema.graphql'), | ||
typegen: path.join(dirname, '../.yoga/nexus.ts'), | ||
schema: path.join(__dirname, './schema.graphql'), | ||
typegen: path.join(__dirname, '../.yoga/nexus.ts'), | ||
}, | ||
typegenAutoConfig: { | ||
sources: [ | ||
{ | ||
source: path.join(dirname, './context.ts'), | ||
source: path.join(__dirname, './context.ts'), | ||
alias: 'ctx', | ||
}, | ||
], | ||
contextType: 'ctx.Context', | ||
}, | ||
}) | ||
|
||
return new ApolloServer({ | ||
const apolloServer = new ApolloServer.ApolloServer({ | ||
schema, | ||
context, | ||
}) | ||
|
||
apolloServer.applyMiddleware({ app, path: '/' }) | ||
|
||
return app | ||
}, | ||
async startServer(express) { | ||
return new Promise<Server>((resolve, reject) => { | ||
const httpServer = express | ||
.listen({ port: 4000 }, () => { | ||
console.log(`🚀 Server ready at http://localhost:4000/`) | ||
|
||
resolve(httpServer) | ||
}) | ||
.on('error', err => reject(err)) | ||
}) | ||
}, | ||
async stopServer(httpServer) { | ||
return httpServer.close() | ||
}, | ||
startServer: server => | ||
server.listen().then(s => console.log(`Server listening at ${s.url}`)), | ||
stopServer: server => server.stop(), | ||
} as Yoga<ApolloServer> | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { prisma, Prisma } from '../.yoga/prisma-client' | ||
import { yogaContext } from 'yoga' | ||
|
||
export interface Context { | ||
prisma: Prisma | ||
} | ||
|
||
export default () => ({ | ||
export default yogaContext(({ req }) => ({ | ||
req, | ||
prisma, | ||
}) | ||
})) |
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
Oops, something went wrong.