apollographql / apollo-server

🌍  Spec-compliant and production ready JavaScript GraphQL server that lets you develop in a schema-first way. Built for Express, Connect, Hapi, Koa, and more.
https://www.apollographql.com/docs/apollo-server/
MIT License
13.77k stars 2.03k forks source link

Using a query with @defer does not add `path` to incremental responses #7893

Closed jer-k closed 3 months ago

jer-k commented 3 months ago

Issue Description

I've been attempting to learn more about how Apollo Server works and also create a working reproduction for https://github.com/apollographql/apollo-client/issues/11870. To create the reproduction, I needed to get the @defer directive working on Apollo Server. I've managed to put all the pieces together to get the multipart responses returning, but the issue I've run into is that a path attribute does not seem to be added to my responses.

The error in the console

TypeError: Cannot read properties of undefined (reading 'length')
    at eval (incrementalResult.js:38:31)
    at Array.forEach (<anonymous>)
    at mergeIncrementalData (incrementalResult.js:36:28)
    at QueryInfo.markResult (QueryInfo.js:278:103)
    at eval (QueryManager.js:794:27)
    at both (asyncMap.js:27:31)

The code in Apollo Client https://github.com/apollographql/apollo-client/blob/7111de266e4ae5b21cf8cb59531db6f8bb9b443f/src/utilities/common/incrementalResult.ts#L53.

If we look at the PR where the defer support was added (https://github.com/apollographql/apollo-server/pull/6827/files) we can see a bunch of tests with content that looks like this

---
content-type: application/json; charset=utf-8
{"hasNext":false,"incremental":[{"path":[],"data":{"delayedFoo":{"bar":"hi"}}}]}
-----

Where "path":[] is present.

The response that my Apollo Server is returning looks like this

---
content-type: application/json; charset=utf-8

{"hasNext":false,"incremental":[{"data":{"stores":[{"name":"First Store","address":"123 Main Street","__typename":"Store"},{"name":"Second Store","address":"567 1st Ave","__typename":"Store"}]}}]}
-----

Notice there is no "path".

From what I could find in the codebase, it appears that path should be added here https://github.com/apollographql/apollo-server/blob/268687db591fed8293eeded1546ae2f8e6f2b6a7/packages/server/src/runHttpQuery.ts#L380.

I'm unsure if I've set up my project wrong or if there is some sort of error from Apollo Server in adding in this path attribute.

Link to Reproduction

https://github.com/jer-k/graphql-rsc-dashboard

Reproduction Steps

The query is located at https://github.com/jer-k/graphql-rsc-dashboard/blob/main/components/client-book-stores.tsx#L7-L25 The Apollo Server implementation code exists here https://github.com/jer-k/graphql-rsc-dashboard/tree/main/graphql

jer-k commented 3 months ago

Issue is resolved moving back to graphql 17 alpha.2

github-actions[bot] commented 2 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.