Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernise JS examples in the documentation #1821

Open
benjie opened this issue Nov 8, 2024 · 6 comments
Open

Modernise JS examples in the documentation #1821

benjie opened this issue Nov 8, 2024 · 6 comments

Comments

@benjie
Copy link
Member

benjie commented Nov 8, 2024

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.

@kasir-barati
Copy link

kasir-barati commented Nov 14, 2024

This is not the only issue. Some examples ain't working at all. Take for instance this one: https://github.com/graphql/graphql.github.io/blob/source/src/pages/graphql-js/running-an-express-graphql-server.mdx

And the way that you should use graphql-http per their doc is like this:

import express from 'express'; // yarn add express
import { createHandler } from 'graphql-http/lib/use/express';
import { schema } from './previous-step';

// Create an express instance serving all methods on `/graphql`
// where the GraphQL over HTTP express request handler is
const app = express();
app.all('/graphql', createHandler({ schema }));

app.listen({ port: 4000 });
console.log('Listening to port 4000');

Note that the current doc is broken and cannot be run without issue.

@kasir-barati
Copy link

BTW to just communicate it clearly. Now I am questioning whether I should read your doc or not. I mean usually I tend to read docs all the time when I start something new. But at this rate I feel what I'll learn from your doc will be something that someone back in 2018 would have learned. Not to mention the NodeJS now is at version 22. While in your doc it is talking about examples being compatible with version 6. I am not sure except some old code bases if anybody else uses Node V6.

@jorydotcom
Copy link
Contributor

@kasir-barati wanna help us fix it? 😄

@kasir-barati
Copy link

Love to if I get the chance. Since TBF I have already done part of it (link to repo). Or at least it is done in TS, but I can get rid of all typings and replace them with JSDoc. But I also need some inputs along the way.

Here is my own doc compiled mainly from: https://graphql.org/graphql-js.

@benjie
Copy link
Member Author

benjie commented Nov 21, 2024

Awesome - would be great to have your help! The graphql-js.org website is currently being rewritten - if you'd like to get involved in that I encourage you to talk with Jovi and Yaacov in #graphql-js on the GraphQL Discord or get involved with the graphql-js-wg: https://github.com/graphql/graphql-js-wg

This issue specifically relates to the /learn pages rather than the /graphql-js pages, and there we're just looking for much simpler changes as there's a lot of editorial already in progress thanks to Mandi's work.

@kasir-barati
Copy link

BTW @benjie I am also going through the /learn. So I am looking forward to this issue being resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants