Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #41 from scalableinternetservices/schemaliink
Browse files Browse the repository at this point in the history
Change HTTP link to Schema link
  • Loading branch information
danielskathyd authored Nov 20, 2020
2 parents 5a1d5da + f7b8ab7 commit 57f4052
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
21 changes: 4 additions & 17 deletions server/src/render.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApolloClient, ApolloProvider, HttpLink, InMemoryCache } from '@apollo/client'
import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client'
import { SchemaLink } from '@apollo/client/link/schema'
import { getDataFromTree } from '@apollo/client/react/ssr'
import { isRedirect, ServerLocation } from '@reach/router'
import 'cross-fetch/polyfill' // enables fetch in node
Expand All @@ -11,24 +12,10 @@ import { Config } from './config'

const Styletron = require('styletron-engine-monolithic')

export function renderApp(req: Request, res: Response) {
export function renderApp(req: Request, res: Response, schema: any) {
const apolloClient = new ApolloClient({
ssrMode: true,
link: new HttpLink({
uri: `http://127.0.0.1:${Config.appserverPort}/graphql`,
credentials: 'same-origin',
fetch: async (uri: any, options: any) => {
const reqBody = JSON.parse(options!.body! as string)
const opName = reqBody.operationName
const actionName = reqBody.variables?.action?.actionName
const authToken = req.cookies.authToken
const headers = authToken ? { ...options.headers, 'x-authtoken': authToken } : options.headers
return fetch(`${uri}?opName=${opName}${actionName ? `&actionName=${actionName}` : ''}`, {
...options,
headers,
})
},
}),
link: new SchemaLink({ schema }),
cache: new InMemoryCache(),
})

Expand Down
2 changes: 1 addition & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ server.express.get('/', (req, res) => {

server.express.get('/app/*', (req, res) => {
console.log('GET /app')
renderApp(req, res)
renderApp(req, res, server.executableSchema)
})

server.express.get(
Expand Down

0 comments on commit 57f4052

Please sign in to comment.