Skip to content

Commit 766c9c3

Browse files
authored
feat: @defer, @stream, websockets support in a createGraphiQLFetcher utility (#1770)
- support for `@defer` and `@stream` in `GraphiQL` itself on fetcher execution and when handling stream payloads - introduce `@graphiql/toolkit` for types and utilities used to compose `GraphiQL` and other related libraries - introduce `@graphiql/create-fetcher` to accept simplified parameters to generate a `fetcher` that covers the most commonly used `graphql-over-http` transport spec proposals. using `meros` for multipart http, and `graphql-ws` for websockets subscriptions. - use `graphql` and `graphql-express` `experimental-defer-stream` branch in development until it's merged - add cypress e2e tests for `@stream` in different scenarios - add some unit tests for `createGraphiQLFetcher`
1 parent 881d8b5 commit 766c9c3

File tree

59 files changed

+1868
-862
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1868
-862
lines changed

.eslintrc.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = {
3030
node: true,
3131
browser: true,
3232
jest: true,
33+
'jest/globals': true,
3334
},
3435

3536
extends: [
@@ -294,6 +295,9 @@ module.exports = {
294295
'react/prefer-stateless-function': 'error',
295296
'react/react-in-jsx-scope': 'error',
296297
'react/self-closing-comp': 'error',
298+
'react/display-name': 'warn',
299+
// Jest rules
300+
'jest/no-conditional-expect': 0,
297301
},
298302

299303
plugins: ['import', 'prefer-object-spread', '@typescript-eslint'],
@@ -310,14 +314,18 @@ module.exports = {
310314
},
311315
},
312316
{
317+
excludedFiles: ['**/cypress/**/*.{js,ts}'],
313318
files: [
314-
'packages/{*graphql-*,graphiql}/src/**',
315319
'**/__{tests,mocks}__/*.{js,jsx,ts,tsx}',
320+
'**/*.spec.{ts,js.jsx.tsx}',
316321
],
317322
extends: ['plugin:jest/recommended'],
318323
env: {
319324
'jest/globals': true,
320325
},
326+
rules: {
327+
'jest/no-conditional-expect': 0,
328+
},
321329
},
322330
// Rules for TypeScript only
323331
{
@@ -326,28 +334,6 @@ module.exports = {
326334
'no-unused-vars': 'off',
327335
},
328336
},
329-
// Rules for Babel & Flow only
330-
{
331-
files: ['packages/codemirror-graphql/src/**/*.js'],
332-
parser: 'babel-eslint',
333-
plugins: ['flowtype', 'babel'],
334-
rules: {
335-
// flowtype (https://github.com/gajus/eslint-plugin-flowtype)
336-
'flowtype/boolean-style': 1,
337-
'flowtype/define-flow-type': 1,
338-
'flowtype/no-dupe-keys': 0,
339-
'flowtype/no-primitive-constructor-types': 1,
340-
'flowtype/no-weak-types': 0,
341-
'flowtype/require-parameter-type': 0,
342-
'flowtype/require-return-type': 0,
343-
'flowtype/require-valid-file-annotation': 0,
344-
'flowtype/require-variable-type': 0,
345-
'flowtype/sort-keys': 0,
346-
'flowtype/type-id-match': 0,
347-
'flowtype/use-flow-type': 1,
348-
'flowtype/valid-syntax': 0,
349-
},
350-
},
351337
{
352338
// Converted from 'dependencies' options in ancient config
353339
files: ['**/spec/**', '**/sample-*/**'],

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ lerna-debug.log
2626
.yarnrc
2727
yarn-1.18.0.js
2828
*.orig
29+
30+
# Local Netlify folder
31+
.netlify

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
engine-strict=true
2+
access=public

examples/graphiql-create-react-app/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
"version": "0.1.11-alpha.8",
44
"private": true,
55
"dependencies": {
6-
"@types/react": "^16.9.34",
7-
"@types/react-dom": "^16.9.6",
86
"graphiql": "file:../../packages/graphiql",
9-
"graphql": "^15.0.0",
7+
"graphql": "experimental-stream-defer",
108
"react": "^16.13.1",
119
"react-dom": "^16.13.1",
1210
"react-scripts": "3.4.1"

examples/graphiql-parcel/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
]
2323
},
2424
"dependencies": {
25-
"@types/react": "^16.9.34",
26-
"@types/react-dom": "^16.9.6",
2725
"graphiql": "file:../../packages/graphiql",
28-
"graphql": "15.0.0",
26+
"graphql": "experimental-stream-defer",
2927
"react": "^16.13.1",
3028
"react-dom": "^16.13.1",
3129
"typescript": "^3.4.4"

examples/graphiql-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"dependencies": {
1313
"graphiql": "file:../../packages/graphiql",
14-
"graphql": "15.0.0",
14+
"graphql": "experimental-stream-defer",
1515
"react": "16.13.1"
1616
},
1717
"devDependencies": {

examples/monaco-graphql-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"start": "cross-env NODE_ENV=development webpack-dev-server"
1212
},
1313
"dependencies": {
14-
"graphql": "14.6.0",
14+
"graphql": "experimental-stream-defer",
1515
"monaco-graphql": "file:../../packages/monaco-graphql",
1616
"prettier": "^2.0.2"
1717
},

functions/schema-demo.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* example using https://github.com/awslabs/aws-serverless-express */
2+
const express = require('express');
3+
const { graphqlHTTP } = require('express-graphql');
4+
const awsServerlessExpress = require('aws-serverless-express');
5+
const schema = require('../packages/graphiql/test/schema');
6+
const cors = require('cors');
7+
8+
const binaryMimeTypes = [
9+
'application/javascript',
10+
'application/json',
11+
'font/eot',
12+
'font/opentype',
13+
'font/otf',
14+
'image/jpeg',
15+
'image/png',
16+
'image/svg+xml',
17+
'text/css',
18+
'text/html',
19+
'text/javascript',
20+
'multipart/mixed',
21+
];
22+
23+
const app = express();
24+
25+
app.use(cors({ origin: '*' }));
26+
27+
// Requests to /graphql redirect to /
28+
app.all('/graphql', (req, res) => res.redirect('/'));
29+
30+
// Finally, serve up the GraphQL Schema itself
31+
app.use(
32+
'/',
33+
graphqlHTTP(() => ({ schema })),
34+
);
35+
36+
const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);
37+
38+
exports.handler = (event, context) =>
39+
awsServerlessExpress.proxy(server, event, context);
40+
41+
// // Server
42+
// app.post('/graphql', graphqlHTTP({ schema }));
43+
44+
// // app.get('/graphql', graphQLMiddleware);
45+
// // Export Lambda handler
46+
47+
// exports.handler = serverless(app, {
48+
// httpMethod: 'POST'
49+
// })

package.json

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"private": true,
33
"license": "MIT",
4-
"workspaces": [
5-
"packages/*",
6-
"examples/*"
7-
],
4+
"workspaces": {
5+
"packages": [
6+
"packages/*",
7+
"examples/*"
8+
]
9+
},
810
"lint-staged": {
911
"*.{js,ts,jsx,tsx}": [
1012
"eslint --fix",
@@ -80,20 +82,25 @@
8082
"@octokit/rest": "^18.0.12",
8183
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
8284
"@testing-library/jest-dom": "^5.4.0",
85+
"@types/aws-serverless-express": "^3.3.3",
8386
"@types/codemirror": "^0.0.90",
87+
"@types/express": "^4.17.11",
8488
"@types/fetch-mock": "^7.3.2",
85-
"@types/jest": "^26.0.8",
86-
"@types/node": "^13.11.1",
89+
"@types/jest": "^26.0.20",
90+
"@types/node": "^14.14.22",
8791
"@types/prettier": "^2.0.0",
8892
"@types/theme-ui": "^0.3.1",
89-
"@typescript-eslint/eslint-plugin": "^2.27.0",
90-
"@typescript-eslint/parser": "^2.27.0",
93+
"@types/ws": "^7.4.0",
94+
"@typescript-eslint/eslint-plugin": "^4.14.0",
95+
"@typescript-eslint/parser": "^4.14.0",
96+
"aws-serverless-express": "^3.4.0",
9197
"babel-eslint": "^10.1.0",
9298
"babel-jest": "^25.3.0",
9399
"conventional-changelog-conventionalcommits": "^4.2.3",
94100
"copy": "^0.3.2",
101+
"cors": "^2.8.5",
95102
"cross-env": "^7.0.2",
96-
"cypress": "^4.3.0",
103+
"cypress": "^4.7.0",
97104
"eslint": "^6.8.0",
98105
"eslint-config-prettier": "^6.10.1",
99106
"eslint-plugin-babel": "^5.3.0",
@@ -104,9 +111,9 @@
104111
"eslint-plugin-prefer-object-spread": "1.2.1",
105112
"eslint-plugin-react": "7.19.0",
106113
"eslint-plugin-react-hooks": "^3.0.0",
114+
"express": "^4.17.1",
107115
"fetch-mock": "6.5.2",
108116
"flow-bin": "^0.119.1",
109-
"graphql": "^15.4.0",
110117
"husky": "^4.2.3",
111118
"jest": "^25.3.0",
112119
"jest-environment-jsdom": "^25.3.0",
@@ -117,9 +124,10 @@
117124
"mkdirp": "^1.0.4",
118125
"prettier": "^2.0.4",
119126
"rimraf": "^3.0.2",
127+
"serverless-http": "^2.7.0",
120128
"ts-jest": "^25.3.1",
121129
"typedoc": "^0.19.2",
122-
"typescript": "^3.9.5",
130+
"typescript": "^4.1.3",
123131
"whatwg-url": "^8.4.0"
124132
}
125133
}

packages/codemirror-graphql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"devDependencies": {
5454
"codemirror": "^5.52.2",
5555
"cross-env": "^7.0.2",
56-
"graphql": "15.4.0",
56+
"graphql": "experimental-stream-defer",
5757
"jsdom": "^16.1.0",
5858
"rimraf": "^3.0.0",
5959
"sane": "2.0.0"

packages/graphiql-2-rfc-context/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777
"cssnano": "^4.1.10",
7878
"error-overlay-webpack-plugin": "^0.4.1",
7979
"express": "4.17.1",
80-
"express-graphql": "0.9.0",
80+
"express-graphql": "experimental-stream-defer",
8181
"file-loader": "6.2.0",
8282
"fork-ts-checker-webpack-plugin": "4.1.3",
83-
"graphql": "^15.4.0",
83+
"graphql": "experimental-stream-defer",
8484
"html-webpack-plugin": "^4.0.4",
8585
"identity-obj-proxy": "^3.0.0",
8686
"jest": "^24.8.0",

packages/graphiql-2-rfc-context/src/components/__tests__/GraphiQL.spec.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ describe('GraphiQL', () => {
251251
expect(container.querySelectorAll('.history-label')).toHaveLength(2);
252252
});
253253

254-
it('will save query if variables are different ', () => {
254+
it('will save query if variables are different', () => {
255255
const { getByTitle, container } = render(
256256
<GraphiQL
257257
fetcher={noOpFetcher}
@@ -276,7 +276,7 @@ describe('GraphiQL', () => {
276276
expect(container.querySelectorAll('.history-label')).toHaveLength(2);
277277
});
278278

279-
it('will save query if headers are different ', () => {
279+
it('will save query if headers are different', () => {
280280
const { getByTitle, getByText, container } = render(
281281
<GraphiQL
282282
fetcher={noOpFetcher}
@@ -308,9 +308,6 @@ describe('GraphiQL', () => {
308308
const MyFunctionalComponent = () => {
309309
return null;
310310
};
311-
const wrap = component => () => (
312-
<div className="test-wrapper">{component}</div>
313-
);
314311

315312
it('properly ignores fragments', () => {
316313
const myFragment = (

packages/graphiql-2-rfc-context/src/utility/__tests__/mergeAst.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const schema = new GraphQLSchema({
3030

3131
describe('MergeAst', () => {
3232
fixtures.forEach(fixture => {
33-
it(fixture.desc, () => {
33+
it(`${fixture.desc}`, () => {
3434
const result = print(mergeAst(parse(fixture.query))).replace(/\s/g, '');
3535
const result2 = print(mergeAst(parse(fixture.query), schema)).replace(
3636
/\s/g,

0 commit comments

Comments
 (0)