Skip to content

Modernise JS examples in the documentation #1821

Open
@benjie

Description

Description

Much of the code in the "learn" docs uses promise-based APIs:

function Query_human(obj, args, context, info) {
return context.db.loadHumanByID(args.id).then(
userData => new Human(userData)
)
}

This would be much easier to read in the more modern async/await code:

async function Query_human(obj, args, context, info) { 
  const userData = await context.db.loadHumanByID(args.id)
  return new Human(userData) 
} 

Motivation

async/await has been around long enough now that this should be the norm, and is much easier to read and reason about. This will also help reduce the need to explain about promises in the documentation (though we will still need to note alternative techniques in other languages).

Collaboration

I do not currently have sufficient bandwidth to make these changes; but if they're not done in a year definitely ping me!

Additional Context

Inspired by @mandiwise's overhaul of the documentation.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions