Code Monkey home page Code Monkey logo

Comments (10)

enisdenjo avatar enisdenjo commented on May 19, 2024 1

There, you can now pass whatever you want for the payload. 😄

from graphql-ws.

enisdenjo avatar enisdenjo commented on May 19, 2024 1

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

from graphql-ws.

enisdenjo avatar enisdenjo commented on May 19, 2024

Nothing should be failing silently. Are you sure the socket is not closed with the error in the close event reason? Keep in mind that the client will retry a few times if the connection gets closed (you might not see the error immediately).

If its indeed failing silently, please make a test or a repro and I will be more than happy to look at it and bring up a fix! (Please make an additional issue)

Furthermore, the server validates messages because they should follow the Protocol's shapes. I'd say the validation for the next message is very forgiving - it requires the data or the errors field to be an object in the payload:

graphql-ws/src/message.ts

Lines 120 to 127 in 0d2f974

case MessageType.Next:
return (
hasOwnStringProperty(val, 'id') &&
hasOwnObjectProperty(val, 'payload') &&
// ExecutionResult
(hasOwnObjectProperty(val.payload, 'data') ||
hasOwnObjectProperty(val.payload, 'errors'))
);

Message you provided is failing because the data field is a string. How does a query that gives you just a string in the data object look like? (just curious 😄)

It does make sense to support whatever for the data field - fix is coming!

from graphql-ws.

n1ru4l avatar n1ru4l commented on May 19, 2024

The example above shows such a query, with the schema and Query Object type 😅

You are right, the client connection gets closed and it will retry connecting. However, since this is a error in general related to the server, I would actually also expect to see that issue logged to the console.

The close reason for socket is also not detailed enough imho. like is the message sent by the client invalid or the one sent back and what exactly is invalid? For a nice DX A more detailed message could be returned.

I would propose to not explicitly check whether payload has a data or errors property. That seems to be an implementation detail of execute to me

from graphql-ws.

enisdenjo avatar enisdenjo commented on May 19, 2024

You can hook up onto the closed event for the client and log all socket closes.

I check just the basics, the simplest form of graphql-js's ExecuteResult (any data or object errors). The message has a super simple form, so it should be rather easy to detect why the message is malformed - hence vague error.

I plan on making the client retry connections on some errors only - classify the fatal ones and report them immediately.

Furthermore, all of server-side error handling issues will go away as soon as #64 lands. You will have full control of error handling and reporting then. Once this lands, tracking if the malformed issue originates from the back or front should be easy. Will keep your insights in mind though!

from graphql-ws.

n1ru4l avatar n1ru4l commented on May 19, 2024

defer and stream AsyncIterables returned from execute will emit a final { hasNext: false } execution result. See src/execution/tests/stream-test.js here: graphql/graphql-js@dec5554#diff-a370dc23e95e90e2b04fe67a3a933e6eb09296c64b4eae7509cd3ae93edaf2ae

from graphql-ws.

enisdenjo avatar enisdenjo commented on May 19, 2024

Oh! Well, thats enough for me. I'll just make it so that the validation makes sure that the payload is present. You can pass whatever you want.

from graphql-ws.

n1ru4l avatar n1ru4l commented on May 19, 2024

Awesome 👏 Thanks for considering this!

from graphql-ws.

enisdenjo avatar enisdenjo commented on May 19, 2024

Thank you for bringing it up!

from graphql-ws.

enisdenjo avatar enisdenjo commented on May 19, 2024

🎉 This issue has been resolved in version 1.13.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

from graphql-ws.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.