3 ms·
What's the difference between this and using Apollo Graphql for requests?
by typon 7y ago
What's the difference between this and using Apollo Graphql for requests?
- bobobooey 7y agoNot 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.
- choward 7y agoWith 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.
- bobobooey 7y agoIsn'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.
- typon 7y agoConsider 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> );
- bobobooey 7y agoYou could still wrap this in a suspense wrapper.
- maaaats 7y agoGraphql is for fetching exactly the data your app needs at that point, suspense is for fetching only the code the app needs at that point.