-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new executor with defer/stream support
- Loading branch information
Showing
19 changed files
with
458 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'graphql-yoga': minor | ||
--- | ||
|
||
Engine and graphql-js version agnostic Defer/Stream support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
examples/defer-stream/__integration-tests__/__snapshots__/defer-stream.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Defer / Stream defer: defer 1`] = ` | ||
"--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 50 | ||
{"data":{"fastField":"I am speed"},"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 78 | ||
{"incremental":[{"data":{"slowField":"I am slow"},"path":[]}],"hasNext":false} | ||
--- | ||
----- | ||
" | ||
`; | ||
|
||
exports[`Defer / Stream stream: stream 1`] = ` | ||
"--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 39 | ||
{"data":{"alphabet":[]},"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["a"],"path":["alphabet",0]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["b"],"path":["alphabet",1]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["c"],"path":["alphabet",2]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["d"],"path":["alphabet",3]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["e"],"path":["alphabet",4]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["f"],"path":["alphabet",5]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["g"],"path":["alphabet",6]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["h"],"path":["alphabet",7]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["i"],"path":["alphabet",8]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 70 | ||
{"incremental":[{"items":["j"],"path":["alphabet",9]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["k"],"path":["alphabet",10]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["l"],"path":["alphabet",11]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["m"],"path":["alphabet",12]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["n"],"path":["alphabet",13]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["o"],"path":["alphabet",14]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["p"],"path":["alphabet",15]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["q"],"path":["alphabet",16]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["r"],"path":["alphabet",17]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["s"],"path":["alphabet",18]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["t"],"path":["alphabet",19]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["u"],"path":["alphabet",20]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["v"],"path":["alphabet",21]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["w"],"path":["alphabet",22]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["x"],"path":["alphabet",23]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["y"],"path":["alphabet",24]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 71 | ||
{"incremental":[{"items":["z"],"path":["alphabet",25]}],"hasNext":true} | ||
--- | ||
Content-Type: application/json; charset=utf-8 | ||
Content-Length: 17 | ||
{"hasNext":false} | ||
--- | ||
----- | ||
" | ||
`; |
59 changes: 59 additions & 0 deletions
59
examples/defer-stream/__integration-tests__/defer-stream.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { yoga } from '../src/yoga' | ||
|
||
describe('Defer / Stream', () => { | ||
it('stream', async () => { | ||
const start = Date.now() | ||
const response = await yoga.fetch('/graphql', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'multipart/mixed', | ||
}, | ||
body: JSON.stringify({ | ||
query: /* GraphQL */ ` | ||
query StreamAlphabet { | ||
alphabet(waitFor: 100) @stream | ||
} | ||
`, | ||
}), | ||
}) | ||
expect(response.status).toEqual(200) | ||
const contentType = response.headers.get('Content-Type') | ||
expect(contentType).toEqual('multipart/mixed; boundary="-"') | ||
const responseText = await response.text() | ||
const end = Date.now() | ||
expect(responseText).toMatchSnapshot('stream') | ||
const diff = end - start | ||
expect(diff).toBeLessThan(2650) | ||
expect(diff > 2550).toBeTruthy() | ||
}) | ||
it('defer', async () => { | ||
const start = Date.now() | ||
const response = await yoga.fetch('/graphql', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'multipart/mixed', | ||
}, | ||
body: JSON.stringify({ | ||
query: /* GraphQL */ ` | ||
query SlowAndFastFieldWithDefer { | ||
... on Query @defer { | ||
slowField(waitFor: 1500) | ||
} | ||
fastField | ||
} | ||
`, | ||
}), | ||
}) | ||
expect(response.status).toEqual(200) | ||
const contentType = response.headers.get('Content-Type') | ||
expect(contentType).toEqual('multipart/mixed; boundary="-"') | ||
const responseText = await response.text() | ||
const end = Date.now() | ||
expect(responseText).toMatchSnapshot('defer') | ||
const diff = end - start | ||
expect(diff).toBeLessThan(1600) | ||
expect(diff > 1450).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.