Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Update supported "Incremental Delivery" format/spec #3007

Merged
merged 17 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-avocados-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/core': minor
---

Update support for the "Incremental Delivery" payload specification, accepting the new `incremental` property on execution results, as per the specification. This will expand support for newer APIs implementing the more up-to-date specification.
5 changes: 5 additions & 0 deletions .changeset/nine-dancers-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/core': minor
---

Update default `Accept` header to include `multipart/mixed` and `application/graphql-response+json`. The former seems to now be a defactor standard-accepted indication for support of the "Incremental Delivery" GraphQL over HTTP spec addition/RFC, and the latter is an updated form of the older `Content-Type` of GraphQL responses, so both the old and new one should now be included.
27 changes: 15 additions & 12 deletions examples/with-defer-stream-directives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "concurrently -k \"vite\" \"node server/index.js\""
"server:apollo": "node server/apollo-server.js",
"server:yoga": "node server/graphql-yoga.js",
"client": "vite",
"start": "run-p client server:yoga"
},
"dependencies": {
"@urql/core": "^2.3.0",
"@urql/exchange-graphcache": "^4.3.0",
"graphql": "15.4.0-experimental-stream-defer.1",
"@apollo/server": "^4.4.1",
"@graphql-yoga/plugin-defer-stream": "^1.7.1",
"@urql/core": "^3.1.1",
"@urql/exchange-graphcache": "^5.0.9",
"graphql": "17.0.0-alpha.2",
"graphql-yoga": "^3.7.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"urql": "^2.0.2"
"urql": "^3.0.3"
},
"devDependencies": {
"@polka/parse": "^1.0.0-next.0",
"@vitejs/plugin-react-refresh": "^1.3.3",
"concurrently": "^6.2.1",
"cors": "^2.8.5",
"graphql-helix": "^1.7.0",
"polka": "^0.5.2",
"vite": "^2.2.4"
"@vitejs/plugin-react-refresh": "^1.3.6",
"graphql-helix": "^1.13.0",
"npm-run-all": "^4.1.5",
"vite": "^2.9.15"
}
}
14 changes: 14 additions & 0 deletions examples/with-defer-stream-directives/server/apollo-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// NOTE: This currently fails because responses for @defer/@stream are not sent
// as multipart responses, but the request fails silently with an empty JSON response payload

const { ApolloServer } = require('@apollo/server');
const { startStandaloneServer } = require('@apollo/server/standalone');
const { schema } = require('./schema');

const server = new ApolloServer({ schema });

startStandaloneServer(server, {
listen: {
port: 3004,
},
});
13 changes: 13 additions & 0 deletions examples/with-defer-stream-directives/server/graphql-yoga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { createYoga } = require('graphql-yoga');
const { useDeferStream } = require('@graphql-yoga/plugin-defer-stream');
const { createServer } = require('http');
const { schema } = require('./schema');

const yoga = createYoga({
schema,
plugins: [useDeferStream()],
});

const server = createServer(yoga);

server.listen(3004);
126 changes: 0 additions & 126 deletions examples/with-defer-stream-directives/server/index.js

This file was deleted.

57 changes: 57 additions & 0 deletions examples/with-defer-stream-directives/server/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const {
GraphQLList,
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
} = require('graphql');

const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: () => ({
alphabet: {
type: new GraphQLList(
new GraphQLObjectType({
name: 'Alphabet',
fields: {
char: {
type: GraphQLString,
},
},
})
),
resolve: async function* () {
for (let letter = 65; letter <= 90; letter++) {
await new Promise(resolve => setTimeout(resolve, 500));
yield { char: String.fromCharCode(letter) };
}
},
},
song: {
type: new GraphQLObjectType({
name: 'Song',
fields: () => ({
firstVerse: {
type: GraphQLString,
resolve: () => "Now I know my ABC's.",
},
secondVerse: {
type: GraphQLString,
resolve: () =>
new Promise(resolve =>
setTimeout(
() => resolve("Next time won't you sing with me?"),
5000
)
),
},
}),
}),
resolve: () =>
new Promise(resolve => setTimeout(() => resolve('goodbye'), 1000)),
},
}),
}),
});

module.exports = { schema };
2 changes: 1 addition & 1 deletion examples/with-defer-stream-directives/src/Songs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const SONGS_QUERY = gql`
firstVerse
...secondVerseFields @defer
}
alphabet @stream(initial_count: 3) {
alphabet @stream(initialCount: 3) {
char
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`on error > returns error data 1`] = `
{
Expand Down Expand Up @@ -590,13 +590,7 @@ exports[`on success > uses a file when given 1`] = `
}
`;

exports[`on success > uses a file when given 2`] = `
{
"accept": "application/graphql+json, application/json",
}
`;

exports[`on success > uses a file when given 3`] = `FormData {}`;
exports[`on success > uses a file when given 2`] = `FormData {}`;

exports[`on success > uses multiple files when given 1`] = `
{
Expand Down Expand Up @@ -737,10 +731,4 @@ exports[`on success > uses multiple files when given 1`] = `
}
`;

exports[`on success > uses multiple files when given 2`] = `
{
"accept": "application/graphql+json, application/json",
}
`;

exports[`on success > uses multiple files when given 3`] = `FormData {}`;
exports[`on success > uses multiple files when given 2`] = `FormData {}`;
2 changes: 0 additions & 2 deletions exchanges/multipart-fetch/src/multipartFetchExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ describe('on success', () => {

expect(data).toMatchSnapshot();
expect(fetchOptions).toHaveBeenCalled();
expect(fetch.mock.calls[0][1].headers).toMatchSnapshot();
expect(fetch.mock.calls[0][1].body).toMatchSnapshot();
});

Expand All @@ -103,7 +102,6 @@ describe('on success', () => {

expect(data).toMatchSnapshot();
expect(fetchOptions).toHaveBeenCalled();
expect(fetch.mock.calls[0][1].headers).toMatchSnapshot();
expect(fetch.mock.calls[0][1].body).toMatchSnapshot();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__snapshots__/client.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`createClient / Client > passes snapshot 1`] = `
Client2 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`on error > returns error data 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should return response data from forwardSubscription observable 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`on error > ignores the error when a result is available 1`] = `
{
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/internal/fetchOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const makeFetchOptions = (
const useGETMethod =
operation.kind === 'query' && !!operation.context.preferGetMethod;
const headers: HeadersInit = {
accept: 'application/graphql+json, application/json',
accept:
'multipart/mixed, application/graphql-response+json, application/graphql+json, application/json',
};
if (!useGETMethod) headers['content-type'] = 'application/json';
const extraOptions =
Expand Down
Loading