-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated to the newest ecosystem dependencies
BREAKING CHANGE: Apollo deprecated the @apollo/federation, we switched to @apollo/subgraph, but that requires changes in the package.json. Updating to this version will break the existing app, unless you follow the upgrades visible in the ./scaffold/package.json file
- Loading branch information
Showing
7 changed files
with
80 additions
and
78 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 |
---|---|---|
@@ -1,26 +1,19 @@ | ||
import express from "express"; | ||
import { RootInterface } from "./root"; | ||
import { dataSources } from "./dataSources"; | ||
|
||
export type GqlContext = AppContext & { | ||
dataSources: ReturnType<typeof dataSources>; | ||
}; | ||
export type GqlContext = RootInterface & { req: RequestType }; | ||
|
||
export type AppContext = RootInterface & { | ||
type RequestType = { | ||
headers: { | ||
[key: string]: string | string[]; | ||
[key: string]: string | string[] | undefined; | ||
}; | ||
jwt?: string; | ||
}; | ||
|
||
export const appContext = (root: RootInterface) => ({ | ||
req, | ||
}: { | ||
req: express.Request; | ||
}): AppContext => { | ||
return { | ||
...root, | ||
headers: req.headers, | ||
jwt: req.cookies.jwt, | ||
}; | ||
}; | ||
export const appContext = | ||
(root: RootInterface) => | ||
async ({ req }: { req: RequestType }): Promise<GqlContext> => { | ||
return { | ||
...root, | ||
req, | ||
}; | ||
}; |
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,30 +1,39 @@ | ||
import { ApolloServer } from "apollo-server-express"; | ||
import express from "express"; | ||
import { ApolloServer } from "@apollo/server"; | ||
import { expressMiddleware } from "@apollo/server/express4"; | ||
import { json } from "body-parser"; | ||
import cors from "cors"; | ||
import cookieParser from "cookie-parser"; | ||
import express from "express"; | ||
import http from "http"; | ||
import { schema } from "~generated/graphql/schema"; | ||
import { appContext } from "~app/context"; | ||
import { dataSources } from "./dataSources"; | ||
import { GqlContext, appContext } from "~app/context"; | ||
import { root } from "./root"; | ||
|
||
const apollo = new ApolloServer<GqlContext>({ | ||
schema, | ||
}); | ||
|
||
export const createApp = () => { | ||
apollo.start().then(async () => { | ||
const app = express(); | ||
|
||
app.use([cookieParser()]); | ||
const httpServer = http.createServer(app); | ||
|
||
const corsOptions = { | ||
origin: 'http://localhost:3000', | ||
credentials: true | ||
} | ||
|
||
const apollo = new ApolloServer({ | ||
schema, | ||
dataSources, | ||
context: appContext(root), | ||
origin: "http://localhost:3000", | ||
credentials: true, | ||
}; | ||
|
||
app.use( | ||
"/graphql", | ||
cors<cors.CorsRequest>(corsOptions), | ||
json(), | ||
expressMiddleware(apollo, { | ||
context: appContext(root), | ||
}), | ||
); | ||
|
||
const port = process.env.PORT || 4000; | ||
httpServer.listen({ port }, () => { | ||
console.log(`🚀 Server ready at http://localhost:${port}/graphql`); | ||
}); | ||
|
||
apollo.applyMiddleware({ app, cors: corsOptions }); | ||
|
||
return app; | ||
}; | ||
|
||
}); |
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 |
---|---|---|
@@ -1,6 +1 @@ | ||
import { createApp } from "./createApp"; | ||
|
||
const port = process.env.PORT || 4000 | ||
createApp().listen({ port }, () => | ||
console.log(`🚀 Server ready at http://localhost:${port}/graphql`) | ||
); | ||
import "./createApp"; |
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