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.

Cannot stringify invalid message; isMessage validation for execution result is too strict

See original GitHub issue

A stream payload published by an AsyncIterable returned by execute (from graphql@15.4.0-experimental-stream-defer.1) cannot be stringified

{
  id: '7aef51de-707e-49e5-8cbf-df1bff572e5f',
  type: 'next',
  payload: { data: 'Friend', path: [ 'streamTest', 2 ], hasNext: true }
}

It fails silently with the following message, I had to dig into node_modules and add a bunch of console.logs before I had access to this message.

Error: Cannot stringify invalid message
    at Object.stringifyMessage (/Users/laurin/projects/stream-defer-demo/node_modules/graphql-ws/cjs/message.js:87:15)

It would be nice if such an error would not be swallowed by default but instead forwarded to the console. The user could then overwrite the default behavior.

Aside from that, this message object (returned from execute) should be accepted as a valid message. I don’t understand why exactly the message sent by the server must be validated - as the server constructs it should be fine? Also, the current validation seems to be rather inflexible and must be updated every time graphql supports a new execution result variation. The responsibility for returning a correct result should be within execute.

Reference code:

type Query {
  greetings: [String]
}
query StreamTestQuery {
  streamTest @stream(initialCount: 1)
}
const Query = new GraphQLObjectType({
  name: "Query",
  fields: {
    streamTest: {
      type: GraphQLList(GraphQLString),
      resolve: async function* () {
        for (const item of ["Hi", "My", "Friend"]) {
          yield item;
          await sleep(1000);
        }
      },
    },
})

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
enisdenjocommented, Nov 14, 2020

BTW, the client now fails immediately for some fatal close event codes. This should improve the DX by bringing a problem up sooner.

1reaction
enisdenjocommented, Nov 14, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

6 Validation with Joi - hapi.js in Action - liveBook · Manning
One of those properties is message, which is a string , containing a summary of the validation error. The details property will contain...
Read more >
API Gateway WebSocket API mapping template reference
A string containing a detailed validation error message. $context.identity.accountId. The AWS account ID associated with the request. $context.identity.
Read more >
Table of Contents - The Web Application Messaging Protocol
This leads to a message parsing and validation control flow that is efficient, simple to implement and simple to code for rigorous message...
Read more >
p As there one instance of the encoder class by endpoint session so ...
Authorization is validated when a request isreceived and before any other action using the user input information.The access token is passed with every...
Read more >
Plug-In API Messages - Oracle Help Center
callProcedureResult: Mobility returns the result of the execution of procedure ... All validation errors are sent to a plug-in within the error message....
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