Skip to content

Commit

Permalink
feat: defer, stream, websockets support in a createGraphiQLFetcher ut…
Browse files Browse the repository at this point in the history
…ility (#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`
- add `changesets` because lerna publish no longer works. get rid of commitlint
  • Loading branch information
acao committed Feb 1, 2021
1 parent 881d8b5 commit 4fa9ca3
Show file tree
Hide file tree
Showing 68 changed files with 2,474 additions and 3,357 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/master/docs/common-questions.md)
10 changes: 10 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "minor",
"ignore": ["example-*", "graphiql-2-rfc-context*"]
}
14 changes: 14 additions & 0 deletions .changeset/early-stingrays-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'graphiql': minor
'@graphiql/create-fetcher': minor
'@graphiql/toolkit': minor
---

`@defer`, `@stream`, and `graphql-ws` 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`
32 changes: 9 additions & 23 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
node: true,
browser: true,
jest: true,
'jest/globals': true,
},

extends: [
Expand Down Expand Up @@ -294,6 +295,9 @@ module.exports = {
'react/prefer-stateless-function': 'error',
'react/react-in-jsx-scope': 'error',
'react/self-closing-comp': 'error',
'react/display-name': 'warn',
// Jest rules
'jest/no-conditional-expect': 0,
},

plugins: ['import', 'prefer-object-spread', '@typescript-eslint'],
Expand All @@ -310,14 +314,18 @@ module.exports = {
},
},
{
excludedFiles: ['**/cypress/**/*.{js,ts}'],
files: [
'packages/{*graphql-*,graphiql}/src/**',
'**/__{tests,mocks}__/*.{js,jsx,ts,tsx}',
'**/*.spec.{ts,js.jsx.tsx}',
],
extends: ['plugin:jest/recommended'],
env: {
'jest/globals': true,
},
rules: {
'jest/no-conditional-expect': 0,
},
},
// Rules for TypeScript only
{
Expand All @@ -326,28 +334,6 @@ module.exports = {
'no-unused-vars': 'off',
},
},
// Rules for Babel & Flow only
{
files: ['packages/codemirror-graphql/src/**/*.js'],
parser: 'babel-eslint',
plugins: ['flowtype', 'babel'],
rules: {
// flowtype (https://github.com/gajus/eslint-plugin-flowtype)
'flowtype/boolean-style': 1,
'flowtype/define-flow-type': 1,
'flowtype/no-dupe-keys': 0,
'flowtype/no-primitive-constructor-types': 1,
'flowtype/no-weak-types': 0,
'flowtype/require-parameter-type': 0,
'flowtype/require-return-type': 0,
'flowtype/require-valid-file-annotation': 0,
'flowtype/require-variable-type': 0,
'flowtype/sort-keys': 0,
'flowtype/type-id-match': 0,
'flowtype/use-flow-type': 1,
'flowtype/valid-syntax': 0,
},
},
{
// Converted from 'dependencies' options in ancient config
files: ['**/spec/**', '**/sample-*/**'],
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/fork.yml.archived

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/issue.yml.archived

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
- name: Setup Node.js 12.x
uses: actions/setup-node@master
with:
node-version: 12.x
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@master
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
15 changes: 0 additions & 15 deletions .github/workflows/review-submitted.yml.archived

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ lerna-debug.log
.yarnrc
yarn-1.18.0.js
*.orig

# Local Netlify folder
.netlify
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
engine-strict=true
access=public
55 changes: 1 addition & 54 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
# Cutting New Releases

We chose a manual process which is pretty simple and flexible because of our conventional commit messages.

If you have NPM privileges, you have the ability to cut new releases of the packages herein.

## Requirements

You'll need:

- `GH_TOKEN` : a github user token as an environment variable
- `git` command line installed, obviously!
- to run `yarn login` first to ensure you're authenticated for publishing
- your npm 2FA should be enabled, and you should have your second factor device handy for publish
- your remote should be named `origin` for github, and should be the ssh url
- (coming soon) GPG key uploaded to account for signing

Note: Always publish from `master`. Always execute `yarn test` beforehand, and check the `examples/graphiql-webpack` to ensure there aren't any webpack build bugs.

## Prereleases

```sh
lerna publish --conventional-prerelease graphiql --otp <your-otp>
```

for a specific package, or leave blank for all packages.

It will automatically generate pre-release versions that reflect the conventional pattern from the commit log - so some packages may end up pre-alpha, others may be pre-minor, etc.

For example, if you made a change to `graphql-language-service-utils` there would be a new version for every single package. But if you made a change to `graphiql` in the commits since the last publish, there should only be a new pre-release version for `graphiql` when you run this command.

You can also `--amend` a previous release upon publishing, overriding the previous git tags

## Graduating Prereleases

Now, after creating and publishing some pre-release versions, if you want to graduate them you can do so with a command that works in very much the same way as above.

```sh
lerna publish --conventional-graduate * --otp <your token>
```

Would graduate all pre-alphas to patch releases, pre-minors to minor releases, etc.

You can also give a comma seperated list of packages, or just a single one, as with `prereleases`

```sh
lerna publish --conventional-graduate codemirror-graphql --otp <your token>
```

## Full Releases

```sh
lerna publish --otp <your token>
```

Will automatically detect and generate changelog/etc with appropriate versions and entries for all subpackage, no need to supply package names or an asterisk
TODO: Redo for `changesets`. See [`Changesets Readme`](./.changeset/README.md)
3 changes: 0 additions & 3 deletions commitlint.config.js

This file was deleted.

4 changes: 1 addition & 3 deletions examples/graphiql-create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
"version": "0.1.11-alpha.8",
"private": true,
"dependencies": {
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.6",
"graphiql": "file:../../packages/graphiql",
"graphql": "^15.0.0",
"graphql": "experimental-stream-defer",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
Expand Down
6 changes: 2 additions & 4 deletions examples/graphiql-parcel/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "graphiql-parcel-example",
"name": "example-graphiql-parcel",
"version": "1.1.10-alpha.8",
"license": "MIT",
"description": "GraphiQL Parcel Example",
Expand All @@ -22,10 +22,8 @@
]
},
"dependencies": {
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.6",
"graphiql": "file:../../packages/graphiql",
"graphql": "15.0.0",
"graphql": "experimental-stream-defer",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"typescript": "^3.4.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/graphiql-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"graphiql": "file:../../packages/graphiql",
"graphql": "15.0.0",
"graphql": "experimental-stream-defer",
"react": "16.13.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/monaco-graphql-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start": "cross-env NODE_ENV=development webpack-dev-server"
},
"dependencies": {
"graphql": "14.6.0",
"graphql": "experimental-stream-defer",
"monaco-graphql": "file:../../packages/monaco-graphql",
"prettier": "^2.0.2"
},
Expand Down
49 changes: 49 additions & 0 deletions functions/schema-demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* example using https://github.com/awslabs/aws-serverless-express */
const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const awsServerlessExpress = require('aws-serverless-express');
const schema = require('../packages/graphiql/test/schema');
const cors = require('cors');

const binaryMimeTypes = [
'application/javascript',
'application/json',
'font/eot',
'font/opentype',
'font/otf',
'image/jpeg',
'image/png',
'image/svg+xml',
'text/css',
'text/html',
'text/javascript',
'multipart/mixed',
];

const app = express();

app.use(cors({ origin: '*' }));

// Requests to /graphql redirect to /
app.all('/graphql', (req, res) => res.redirect('/'));

// Finally, serve up the GraphQL Schema itself
app.use(
'/',
graphqlHTTP(() => ({ schema })),
);

const server = awsServerlessExpress.createServer(app, null, binaryMimeTypes);

exports.handler = (event, context) =>
awsServerlessExpress.proxy(server, event, context);

// // Server
// app.post('/graphql', graphqlHTTP({ schema }));

// // app.get('/graphql', graphQLMiddleware);
// // Export Lambda handler

// exports.handler = serverless(app, {
// httpMethod: 'POST'
// })
27 changes: 0 additions & 27 deletions lerna.json

This file was deleted.

Loading

0 comments on commit 4fa9ca3

Please sign in to comment.