re: GraphQL for beginners VIEW POST

re: Say I have a MSSQL/MySql/PostgreSQL database with two tables, to keep it simple, with say 10 and 20 fields respectively, I would have to write a se...

You don't have to write resolvers for each field. By default, if you didn't specify a resolver for a field, GraphQL will return an object property with the same name.

Imagine that you have "Spaceships" table with 30 fields. This will be our "main" resolver for querying all spaceships:

Query: {
    spaceships(obj, args, context, info) {
      return db.findAllSpaceships()

And now, because we didn't write resolvers for Spaceship fields, GraphQL will return spaceship.model if we queried model field, spaceship.weight for weight field and same applies for every other queryable field. Hope that this makes sense 🙂

code of conduct - report abuse