Hacker News new | ask | show | jobs
by verbin217 3908 days ago
https://github.com/graphql/graphql-js

Just implement resolve.

2 comments

If you have two fields in a query, does that mean two resolve functions? If I using a SQL database and the two fields were stored on two columns on the same table, wouldn't that cause 2 SQL queries to be run?
Only if each field required loading a new row, and even then batching can be used to turn this back into one query.

eg: { firstName, lastName } doesn't need to load new rows but { mother { name }, father { name } } does need to load new rows.

DataLoader (https://github.com/facebook/dataloader) is a small utility which makes batching and caching database requests straight forward.

Yes. But only one http request. If they're both the same query but access a different field you might be able to cache it.
Sangria in Scala has a mechanism called "Deferred" that lets you specify that it should ask you to resolve objects of a certain type all at once at the end, and you would do a single SQL query per object type there.

If the JavaScript implementation doesn't have something like this, perhaps it can be hacked on top.

and you'll end up with an endpoint that can potentially bomb your datastore

    query User {
      friends {
        friends {
          friends {
            ...
          }
        }
      }
    }
how do you prevent something like this happening on graphQL backed with a series of resolves that query a SQL database?
Limit recursion with a max depth parameter (sangria)
I don't need that many levels to make it explode and you probably don't want to set a very low max depth since it beats the purpose of graphql itself.