Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 9f0c8df

Browse files
kyarikIvanGoncharov
authored andcommitted
Update Node and TypeScript versions in tests (#765)
1 parent baa2561 commit 9f0c8df

File tree

9 files changed

+59
-162
lines changed

9 files changed

+59
-162
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
runs-on: ubuntu-latest
117117
strategy:
118118
matrix:
119-
node_version_to_setup: [10, 12, 14, 15]
119+
node_version_to_setup: [10, 12, 14, 16]
120120
steps:
121121
- name: Checkout repo
122122
uses: actions/checkout@v2

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,8 @@ app.listen(4000);
7474
const express = require('express');
7575
const { graphqlHTTP } = require('express-graphql');
7676

77-
const typeDefs = require('./schema');
78-
const resolvers = require('./resolvers');
79-
const { makeExecutableSchema } = require('graphql-tools');
80-
const schema = makeExecutableSchema({
81-
typeDefs: typeDefs,
82-
resolvers: resolvers,
83-
});
84-
85-
const { execute, subscribe } = require('graphql');
8677
const { createServer } = require('http');
78+
const { execute, subscribe } = require('graphql');
8779
const { SubscriptionServer } = require('subscriptions-transport-ws');
8880

8981
const PORT = 4000;
@@ -93,7 +85,7 @@ var app = express();
9385
app.use(
9486
'/graphql',
9587
graphqlHTTP({
96-
schema: schema,
88+
schema: MyGraphQLSchema,
9789
graphiql: { subscriptionEndpoint: `ws://localhost:${PORT}/subscriptions` },
9890
}),
9991
);
@@ -102,7 +94,7 @@ const ws = createServer(app);
10294

10395
ws.listen(PORT, () => {
10496
// Set up the WebSocket for handling GraphQL subscriptions.
105-
new SubscriptionServer(
97+
SubscriptionServer.create(
10698
{
10799
execute,
108100
subscribe,
@@ -142,7 +134,7 @@ The `graphqlHTTP` function accepts the following options:
142134
- **`headers`**: An optional string of initial state for the header editor. Only makes sense if headerEditorEnabled is `true`.
143135
Defaults to empty.
144136

145-
- **`subscriptionEndpoint`**: An optional GraphQL string contains the WebSocket server url for subscription.
137+
- **`subscriptionEndpoint`**: An optional string contains the WebSocket server url for subscription.
146138

147139
- **`websocketClient`**: An optional GraphQL string for websocket client used for subscription, `v0`: subscriptions-transport-ws, `v1`: graphql-ws. Defaults to `v0` if not provided
148140

examples/index.ts

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,72 @@
1+
import { createServer } from 'http';
2+
13
import express from 'express';
2-
import { buildSchema } from 'graphql';
4+
import { execute, subscribe, buildSchema } from 'graphql';
5+
import { SubscriptionServer } from 'subscriptions-transport-ws';
36

47
import { graphqlHTTP } from '../src';
58

69
// Construct a schema, using GraphQL schema language
710
const schema = buildSchema(`
811
type Query {
9-
hello: String
12+
hello: String!
13+
}
14+
15+
type Subscription {
16+
currentTime: String!
1017
}
1118
`);
1219

1320
// The root provides a resolver function for each API endpoint
1421
const rootValue = {
1522
hello: () => 'Hello world!',
23+
currentTime: () => currentTimeGenerator(),
1624
};
1725

26+
async function* currentTimeGenerator() {
27+
while (true) {
28+
const currentTime = (new Date()).toLocaleTimeString();
29+
console.log('Pushed current time over subscriptions: ' + currentTime);
30+
yield { currentTime };
31+
32+
await later(1);
33+
}
34+
}
35+
36+
function later(delayInSeconds: number) {
37+
return new Promise((resolve) => setTimeout(resolve, delayInSeconds * 1000));
38+
}
39+
40+
const PORT = 4001;
1841
const app = express();
1942
app.use(
2043
'/graphql',
2144
graphqlHTTP({
2245
schema,
2346
rootValue,
24-
graphiql: { headerEditorEnabled: true },
47+
graphiql: {
48+
headerEditorEnabled: true,
49+
subscriptionEndpoint: `ws://localhost:${PORT}/subscriptions`,
50+
},
2551
}),
2652
);
27-
app.listen(4000);
28-
console.log('Running a GraphQL API server at http://localhost:4000/graphql');
53+
54+
const ws = createServer(app);
55+
56+
ws.listen(PORT, () => {
57+
// Set up the WebSocket for handling GraphQL subscriptions.
58+
SubscriptionServer.create(
59+
{
60+
execute,
61+
subscribe,
62+
schema,
63+
rootValue,
64+
},
65+
{
66+
server: ws,
67+
path: '/subscriptions',
68+
},
69+
);
70+
});
71+
72+
console.log(`Running a GraphQL API server at http://localhost:${PORT}/graphql`);

examples/index_subscription.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

examples/index_subscription_legacy.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

examples/schema.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

integrationTests/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"node-10": "npm:[email protected]",
1010
"node-12": "npm:[email protected]",
1111
"node-14": "npm:[email protected]",
12-
"node-15": "npm:node@15.x.x"
12+
"node-16": "npm:node@16.x.x"
1313
}
1414
}

integrationTests/ts/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"typescript-3.8": "npm:[email protected]",
1515
"typescript-3.9": "npm:[email protected]",
1616
"typescript-4.0": "npm:[email protected]",
17-
"typescript-4.1": "npm:[email protected]"
17+
"typescript-4.1": "npm:[email protected]",
18+
"typescript-4.2": "npm:[email protected]",
19+
"typescript-4.3": "npm:[email protected]"
1820
}
1921
}

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848
"check:spelling": "cspell '**/*'",
4949
"check:integrations": "mocha --full-trace integrationTests/*-test.js",
5050
"build:npm": "node resources/build-npm.js",
51-
"start": "node -r ./resources/register.js examples/index.ts",
52-
"start:subscription": "node -r ./resources/register.js examples/index_subscription.ts",
53-
"start:subscription_legacy": "node -r ./resources/register.js examples/index_subscription_legacy.ts"
51+
"start": "node -r ./resources/register.js examples/index.ts"
5452
},
5553
"dependencies": {
5654
"accepts": "^1.3.7",
@@ -100,7 +98,6 @@
10098
"react-dom": "16.14.0",
10199
"restify": "8.5.1",
102100
"sinon": "9.2.1",
103-
"subscriptions-transport-ws": "0.9.18",
104101
"supertest": "6.0.1",
105102
"ts-node": "9.0.0",
106103
"typescript": "4.1.2",

0 commit comments

Comments
 (0)