Skip to content

Commit

Permalink
Add Apollo Server Integration Testsuite (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnabhan committed Nov 1, 2022
1 parent 60f1200 commit 0df99b7
Show file tree
Hide file tree
Showing 17 changed files with 8,278 additions and 2,330 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ jobs:
- run: npm ci
- run: npm run check

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- uses: google/wireit@setup-github-actions-caching/v1
- run: npm ci
- run: npm run test

on:
push:
branches:
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.next/
.vercel
.wireit/
dist/
node_modules/
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.next/
.vercel
.wireit/
dist/

Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ An Apollo Server integration for use with Next.js.
First create a Next.js API route by creating a file at for example `pages/api/graphql.ts`.
This route will be accessible at `/api/graphql`.

Next create an Apollo Server instance and pass it to `startServerAndCreateLambdaHandler`:
Next create an Apollo Server instance and pass it to `startServerAndCreateNextHandler`:

```js
import { ApolloServer } from '@apollo/server';
import { startServerAndCreateNextHandler } from '@as-integrations/next';
import { gql } from 'graphql-tag';

const resolvers = {
Query: {
hello: () => 'world',
},
};

const typeDefs = `#graphql
const typeDefs = gql`
type Query {
hello: String
}
Expand All @@ -33,10 +34,12 @@ const server = new ApolloServer({
export default startServerAndCreateNextHandler(server);
```

You may also pass a context function to `startServerAndCreateNextHandler`:
You may also pass a context function to `startServerAndCreateNextHandler` as such:

```js
export default startServerAndCreateNextHandler(server, { context: async (req, res) => ({ req, res }) });
export default startServerAndCreateNextHandler(server, {
context: async (req, res) => ({ req, res, user: await getLoggedInUser(req) }),
});
```

The Next.js `req` and `res` objects are passed along to the context function.
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testMatch: ['**/src/__tests__/integration.test.ts'],
transform: {
'^.+\\.(js|ts)$': ['babel-jest', { plugins: ['tsconfig-paths-module-resolver'], presets: ['next/babel'] }],
},
};
Loading

0 comments on commit 0df99b7

Please sign in to comment.