Skip to content

Commit

Permalink
Fix middleware and integration test for it (#409)
Browse files Browse the repository at this point in the history
* Fix middleware and integration test for it

Fix #404 #403

* add permission

* update deps
  • Loading branch information
IvanGoncharov committed Sep 23, 2024
1 parent 99cdd6b commit 2915d2d
Show file tree
Hide file tree
Showing 22 changed files with 813 additions and 814 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read # for actions/checkout
pull-requests: write # for actions/dependency-review-action to publish summary
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ services:
dockerfile: ./example/webpack/Dockerfile
stdin_open: true
tty: true
serve-express-example:
build:
context: .
dockerfile: ./example/express-server/Dockerfile
stdin_open: true
tty: true
test:
depends_on:
- serve-webpack-example
- serve-express-example
build:
context: .
dockerfile: ./tests/Dockerfile
Expand All @@ -29,6 +36,9 @@ services:
- ./playwright-report:/app/playwright-report
command: npx playwright test
update-snapshots:
depends_on:
- serve-webpack-example
- serve-express-example
build:
context: .
dockerfile: ./tests/Dockerfile
Expand Down
16 changes: 16 additions & 0 deletions example/express-server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# syntax=docker/dockerfile:1

FROM node:20

WORKDIR /app

COPY ./graphql-voyager-*.tgz graphql-voyager.tgz

COPY ./example/express-server ./example/express-server

WORKDIR example/express-server
RUN npm install
RUN npm test

EXPOSE 9090
CMD npm start
23 changes: 23 additions & 0 deletions example/express-server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as express from 'express';
import { createHandler } from 'graphql-http/lib/use/express';
import { express as voyagerMiddleware } from 'graphql-voyager/middleware';

import { schema } from './schema';

const PORT = 9090;
const app = express();

app.use('/graphql', createHandler({ schema }));
app.use(
'/voyager',
voyagerMiddleware({
endpointUrl: '/graphql',
displayOptions: {
sortByAlphabet: true,
},
}),
);

app.listen(PORT, () => {
console.log(`Started on http://localhost:${PORT}/voyager`);
});
19 changes: 19 additions & 0 deletions example/express-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": "true",
"description": "An example using GraphQL-Voyager",
"scripts": {
"start": "ts-node index.ts",
"test": "tsc"
},
"dependencies": {
"express": "4.21.0",
"graphql": "16.9.0",
"graphql-http": "1.22.1",
"graphql-voyager": "../../graphql-voyager.tgz"
},
"devDependencies": {
"@types/express": "4.17.21",
"ts-node": "10.9.2",
"typescript": "4.9.5"
}
}
103 changes: 103 additions & 0 deletions example/express-server/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { buildSchema } from 'graphql';

export const schema = buildSchema(`
enum TestEnum {
"A rosy color"
RED
"The color of martians and slime"
GREEN
"A feeling you might have if you can't use GraphQL"
BLUE
}
input TestInput {
string: String
int: Int
float: Float
boolean: Boolean
id: ID
enum: TestEnum
object: TestInput
# List
listString: [String]
listInt: [Int]
listFloat: [Float]
listBoolean: [Boolean]
listID: [ID]
listEnum: [TestEnum]
listObject: [TestInput]
}
"The interface"
interface TestInterface {
"Common name string."
name: String
}
type First implements TestInterface {
"Common name string for First."
name: String
first: [TestInterface]
}
type Second implements TestInterface {
"Common name string for Second."
name: String
second: [TestInterface]
}
union TestUnion = First | Second
type Test {
"\`test\` field from \`Test\` type."
test: Test
"> union field from Test type, block-quoted."
union: TestUnion
"id field from Test type."
id: ID
"Is this a test schema? Sure it is."
isTest: Boolean
hasArgs(
string: String
int: Int
float: Float
boolean: Boolean
id: ID
enum: TestEnum
object: TestInput
# List
listString: [String]
listInt: [Int]
listFloat: [Float]
listBoolean: [Boolean]
listID: [ID]
listEnum: [TestEnum]
listObject: [TestInput]
): String
}
"This is a simple mutation type"
type MutationType {
"Set the string field"
setString(value: String): String
}
"This is a simple subscription type"
type SubscriptionType {
"Subscribe to the test type"
subscribeToTest(id: String): Test
}
schema {
query: Test
mutation: MutationType
subscription: SubscriptionType
}
`);
15 changes: 15 additions & 0 deletions example/express-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"strict": true,
"noEmit": true,
"module": "esnext",
"moduleResolution": "node",
"target": "es2021"
},
"include": ["./index.ts"],
"ts-node": {
"compilerOptions": {
"module": "CommonJS"
}
}
}
27 changes: 0 additions & 27 deletions example/middleware/express.js

This file was deleted.

48 changes: 0 additions & 48 deletions example/middleware/hapi.js

This file was deleted.

28 changes: 0 additions & 28 deletions example/middleware/koa.js

This file was deleted.

21 changes: 0 additions & 21 deletions example/middleware/package.json

This file was deleted.

Loading

0 comments on commit 2915d2d

Please sign in to comment.