Git Product home page Git Product logo

graphql-ruby-urql-stream-example's Introduction

This is a copy of urql's stream example, with the server ported to Sinatra (server/server.rb) and Rails stream_server/

Install dependencies:

yarn install

To start the javascript server:

yarn run start

Or, to start the Sinatra server:

yarn run startruby

Or, to start the Rails server:

cd stream_server
rails server
# Run the JS client separately as described below

Alternatively, start the client with yarn run vite, then start the JS server with node server/index.js or the Ruby server with ruby server/server.rb.

Caveats

There are some differences between the Ruby server's behavior and the JS server.

  • Most notably, the JS server runs multiple "setTimeout" waits at the same time, so secondVerse arrives in the middle of the stream of letters. Ruby, on the other hand, runs one sleep at a time, so letters must pause while secondVerse is sleeping. This could probably be improved by use GraphQL::Dataloader, nonblocking: true, and re-working those fields to use Dataloader sources.

  • Where the alphabet field pauses is slightly different. The JS server uses an iterator-type pattern and pauses while enumerating the alphabet. Ruby, on the other hand, pauses before the char field.

    In my opinion, this is the right approach to @stream in a Ruby/Rails context. Consider a list of items fetched from ActiveRecord: the whole list is returned at once, after a pause (waiting for the SQL query to return). At that point, you'd want to return the results for each item separately. That is, if each item has many selections on it, you'd want to run those "sub-queries" independently.

    (You could get a different behavior by using @defer on the list. This exclude the list from the initial response, sending the whole selection in one patch later.)

    Maybe I'm wrong -- is there an advantage in a Ruby/Rails context to supporting pauses between list items? If so, I bet the use of .each in lib/graphql/execution/interpreter/runtime.rb could be expanded to properly support Ruby enumerators.

  • Weirdly, Sinatra doesn't work right with this example when you set Transfer-Encoding: chunked in Ruby -- can't figure out why.

graphql-ruby-urql-stream-example's People

Contributors

jovanni-dev avatar topdeveloper-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.