question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Persistent queries issue with GraphQLi error

See original GitHub issue

The new code added in the persistent queries commit https://github.com/sysgears/apollo-fullstack-starter-kit/commit/de2fdec1e0182bb949ac89020c8d2f0298c72946 breaks GraphQLi.

TypeError: req.body.map is not a function

The following code in src/server/api_server assumes that all req.body are arrays.

app.use(
    '/graphql',
    (req, resp, next) => {
        req.body = req.body.map(body => {
          return {
            query: invertedMap[ body.id ],
            ...body
          };
        });
      next();
    },
  );

I have not investigated what is involved with persistent queries so I cannot say this fix is correct, but this does protect the map from getting called on a non-array:

import { invert, isArray } from 'lodash';
...
app.use(
    '/graphql',
    (req, resp, next) => {
      if (isArray(req.body)) {
        req.body = req.body.map(body => {
          return {
            query: invertedMap[ body.id ],
            ...body
          };
        });
      }
      next();
    },
  );

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mitjadecommented, Apr 9, 2017

@vlasenko I think this ok. As long as you can still use GraphQL in dev mode this is fine with me.

0reactions
zirhocommented, Apr 11, 2017

Nope not working. Fresh started. Go to graphiql by the button up right corner. Try to get post with Id.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automatic persisted queries - Apollo GraphQL Docs
A persisted query is a query string that's cached on the server side, along with its unique identifier (always its SHA-256 hash). Clients...
Read more >
Automatic persisted query in Apollo Client and Server is not ...
The problem is the formatError function. @apollo/client needs to know when it has to resend the query and it uses the GraphQL error...
Read more >
Top GraphQL Errors and How to fix them
When there is a network error while trying to contact a GraphQL server, due to either the server being down or timeouts etc,...
Read more >
Using Persisted Queries · - OneGraph
Persisted queries are an advanced GraphQL feature that allow clients to pre-register queries with the server. In a typical workflow, ...
Read more >
GraphQL error handling to the max with Typescript, codegen ...
In the first version of the query resolver, we were returning objects that matched the GraphQL types and were tagged with the __typename...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found