Skip to content

Commit

Permalink
updated test script and server start
Browse files Browse the repository at this point in the history
  • Loading branch information
ruheni committed Apr 9, 2021
1 parent 7b84cd6 commit 9c84397
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Let's finally add some npm scripts to simplify our future workflows
```json file=package.json
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
+ "dev": "ts-node-dev --transpile-only --no-notify api/server.ts",
+ "dev": "ts-node-dev --transpile-only --no-notify api/index.ts",
+ "build": "tsc"
}
```
Expand All @@ -67,7 +67,7 @@ Let's finally add some npm scripts to simplify our future workflows
```json copy
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "ts-node-dev --transpile-only --no-notify api/server.ts",
"dev": "ts-node-dev --transpile-only --no-notify api/index.ts",
"build": "tsc"
},
```
Expand Down Expand Up @@ -106,14 +106,19 @@ export const schema = makeSchema({

Finally, we'll setup the GraphQL server. We'll intentionally separate the server instantiation from the server listening to make testing easier later.

Create an `api/server.ts` file and add the following code to instantiate your GraphQL server
Create `api/server.ts` and `api/index.ts` files and add the following code to instantiate your GraphQL server:

```ts copy
// api/server.ts
import { ApolloServer } from 'apollo-server'
import { schema } from './schema'

const server = new ApolloServer({ schema })
export const server = new ApolloServer({ schema })
```

```ts copy
// api/index.ts
import { server } from './server.ts'

server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ import { ApolloServer } from 'apollo-server'
+import { context } from './context'
import { schema } from './schema'

const server = new ApolloServer({
export const server = new ApolloServer({
schema,
+ context
})

server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
})
```

</tab>
Expand All @@ -100,14 +96,10 @@ import { ApolloServer } from 'apollo-server'
import { context } from './context'
import { schema } from './schema'

const server = new ApolloServer({
export const server = new ApolloServer({
schema,
context
})

server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
})
```

</tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Then, configure jest and npm scripts in your `package.json`

```json
"scripts": {
"dev": "ts-node-dev --transpile-only --no-notify api/app",
"dev": "ts-node-dev --transpile-only --no-notify api/index.ts",
"build": "tsc",
+ "generate": "ts-node --transpile-only api/schema",
+ "test": "npm run generate && jest"
Expand All @@ -58,7 +58,7 @@ Then, configure jest and npm scripts in your `package.json`

```json
"scripts": {
"dev": "ts-node-dev --transpile-only --no-notify api/app",
"dev": "ts-node-dev --transpile-only --no-notify api/index.ts",
"build": "tsc",
"generate": "ts-node --transpile-only api/schema",
"test": "npm run generate && jest"
Expand Down

0 comments on commit 9c84397

Please sign in to comment.