From cb036f1def9cd733543fa336dc843b2628312f3c Mon Sep 17 00:00:00 2001 From: jdecroock Date: Tue, 14 Mar 2023 13:34:49 +0100 Subject: [PATCH 1/4] avoid using multipart/mixed without streaming directives --- packages/core/src/internal/fetchOptions.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/src/internal/fetchOptions.ts b/packages/core/src/internal/fetchOptions.ts index f3961931d6..eacb470265 100644 --- a/packages/core/src/internal/fetchOptions.ts +++ b/packages/core/src/internal/fetchOptions.ts @@ -88,9 +88,14 @@ export const makeFetchOptions = ( ): RequestInit => { const useGETMethod = operation.kind === 'query' && !!operation.context.preferGetMethod; + + const hasStreamingDirective = + body?.query?.includes('@defer') || body?.query?.includes('@stream'); + const headers: HeadersInit = { - accept: - 'multipart/mixed, application/graphql-response+json, application/graphql+json, application/json', + accept: `${ + hasStreamingDirective ? 'multipart/mixed, ' : '' + }application/graphql-response+json, application/graphql+json, application/json`, }; if (!useGETMethod) headers['content-type'] = 'application/json'; const extraOptions = From 4cc5092a5ec1c40a93b46bfa661ac507bb1c7b05 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Tue, 14 Mar 2023 13:37:55 +0100 Subject: [PATCH 2/4] only add streaming accept header when needed --- .changeset/early-crabs-draw.md | 5 +++++ packages/core/src/internal/fetchOptions.ts | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/early-crabs-draw.md diff --git a/.changeset/early-crabs-draw.md b/.changeset/early-crabs-draw.md new file mode 100644 index 0000000000..b27478ec9d --- /dev/null +++ b/.changeset/early-crabs-draw.md @@ -0,0 +1,5 @@ +--- +'@urql/core': patch +--- + +only add `multipart/mixed` when we see one of the streaming directives diff --git a/packages/core/src/internal/fetchOptions.ts b/packages/core/src/internal/fetchOptions.ts index eacb470265..b9e70aa600 100644 --- a/packages/core/src/internal/fetchOptions.ts +++ b/packages/core/src/internal/fetchOptions.ts @@ -89,6 +89,8 @@ export const makeFetchOptions = ( const useGETMethod = operation.kind === 'query' && !!operation.context.preferGetMethod; + // Alternatively we could use visit() to see if we find any of the two + // directives const hasStreamingDirective = body?.query?.includes('@defer') || body?.query?.includes('@stream'); From 699e84d2345e4351faffb3adcc0a3b5ada407236 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Tue, 14 Mar 2023 13:51:52 +0100 Subject: [PATCH 3/4] move to end of accept headers isntead --- .changeset/early-crabs-draw.md | 3 ++- packages/core/src/internal/fetchOptions.ts | 10 ++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.changeset/early-crabs-draw.md b/.changeset/early-crabs-draw.md index b27478ec9d..5ab50e4f64 100644 --- a/.changeset/early-crabs-draw.md +++ b/.changeset/early-crabs-draw.md @@ -2,4 +2,5 @@ '@urql/core': patch --- -only add `multipart/mixed` when we see one of the streaming directives +move `multipart/mixed` to the last `Accept` header to avoid breaking +`react-native-fetch` diff --git a/packages/core/src/internal/fetchOptions.ts b/packages/core/src/internal/fetchOptions.ts index b9e70aa600..8540a3d464 100644 --- a/packages/core/src/internal/fetchOptions.ts +++ b/packages/core/src/internal/fetchOptions.ts @@ -89,15 +89,9 @@ export const makeFetchOptions = ( const useGETMethod = operation.kind === 'query' && !!operation.context.preferGetMethod; - // Alternatively we could use visit() to see if we find any of the two - // directives - const hasStreamingDirective = - body?.query?.includes('@defer') || body?.query?.includes('@stream'); - const headers: HeadersInit = { - accept: `${ - hasStreamingDirective ? 'multipart/mixed, ' : '' - }application/graphql-response+json, application/graphql+json, application/json`, + accept: + 'application/graphql-response+json, application/graphql+json, application/json, multipart/mixed', }; if (!useGETMethod) headers['content-type'] = 'application/json'; const extraOptions = From 8e27ed92f90503db95d11fa5b5429e69800a014d Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 14 Mar 2023 14:03:02 +0100 Subject: [PATCH 4/4] Update .changeset/early-crabs-draw.md Co-authored-by: Phil Pluckthun --- .changeset/early-crabs-draw.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/early-crabs-draw.md b/.changeset/early-crabs-draw.md index 5ab50e4f64..c3665a6ced 100644 --- a/.changeset/early-crabs-draw.md +++ b/.changeset/early-crabs-draw.md @@ -2,5 +2,4 @@ '@urql/core': patch --- -move `multipart/mixed` to the last `Accept` header to avoid breaking -`react-native-fetch` +Move `multipart/mixed` to end of `Accept` header to avoid cauing Yoga to unnecessarily use it.