Hacker News new | ask | show | jobs
by bobobooey 2391 days ago
Not sure what you mean...GraphQL is just the API endpoint. Using GQL or REST wouldn't make a difference on how suspense works.

You'd still query and display your data in the same way. Suspense will just be a wrapper around the component displaying the data.

2 comments

Consider this code snippet using Apollo React Client:

    const Dogs = ({ onDogSelected }) => (
      <Query query={GET_DOGS}>
        {({ loading, error, data }) => {
          if (loading) return 'Loading...';
          if (error) return `Error! ${error.message}`;

          return (
            <select name="dog" onChange={onDogSelected}>
              {data.dogs.map(dog => (
                <option key={dog.id} value={dog.breed}>
                  {dog.breed}
                </option>
              ))}
            </select>
          );
        }}
      </Query>
    );
You could still wrap this in a suspense wrapper.
With GraphQL you could in theory grab all the data a page needs in one request. Suspense seems to only be useful if you are making multiple requests. Not sure what Apollo has to do with anything though.
Isn't still possible to wait for the data from that one request to be loaded? I'm also curious on how this will work with subscriptions.