Skip to content

Commit 87328dc

Browse files
committed
Redesign Code Page
1 parent ade2339 commit 87328dc

26 files changed

+2861
-353
lines changed

data/js-graphql-clients.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[
2+
{
3+
"name": "Relay",
4+
"description": "Facebook's framework for building React applications that talk to a GraphQL backend.",
5+
"url": "https://facebook.github.io/relay/",
6+
"npm": "react-relay",
7+
"github": "facebook/relay"
8+
},
9+
{
10+
"name": "Apollo Client",
11+
"description": "A powerful JavaScript GraphQL client, designed to work well with React, React Native, Angular 2, or just plain JavaScript.",
12+
"url": "http://apollographql.com/client/",
13+
"npm": "@apollo/client",
14+
"github": "apollographql/apollo-client"
15+
},
16+
{
17+
"name": "GraphQL Request",
18+
"description": "A simple and flexible JavaScript GraphQL client that works in all JavaScript environments (the browser, Node.js, and React Native) - basically a lightweight wrapper around `fetch`.",
19+
"url": "https://github.com/prisma/graphql-request",
20+
"npm": "graphql-request",
21+
"github": "prisma-labs/graphql-request"
22+
},
23+
{
24+
"name": "Lokka",
25+
"description": "A simple JavaScript GraphQL client that works in all JavaScript environments (the browser, Node.js, and React Native).",
26+
"url": "https://github.com/kadirahq/lokka",
27+
"npm": "lokka",
28+
"github": "kadirahq/lokka"
29+
},
30+
{
31+
"name": "nanogql",
32+
"description": "Tiny GraphQL client library using template strings.",
33+
"url": "https://github.com/yoshuawuyts/nanogql",
34+
"npm": "nanographql",
35+
"github": "yoshuawuyts/nanographql"
36+
},
37+
{
38+
"name": "gq-loader",
39+
"description": "A simple JavaScript GraphQL client,Let the *.gql file be used as a module through webpack loader.",
40+
"url": "https://github.com/Houfeng/gq-loader",
41+
"npm": "gq-loader",
42+
"github": "Houfeng/gq-loader"
43+
},
44+
{
45+
"name": "AWS Amplify",
46+
"description": "A JavaScript library for application development using cloud services, which supports GraphQL backend and React components for working with GraphQL data.",
47+
"url": "https://docs.amplify.aws/",
48+
"npm": "aws-amplify",
49+
"github": "aws-amplify/amplify-js"
50+
},
51+
{
52+
"name": "Grafoo",
53+
"description": "An all purpose GraphQL client with view layer integrations for multiple frameworks in just 1.6kb.",
54+
"url": "https://github.com/grafoojs/grafoo",
55+
"npm": "@grafoo/core",
56+
"github": "grafoojs/grafoo"
57+
},
58+
{
59+
"name": "urql",
60+
"description": "A highly customizable and versatile GraphQL client for React.",
61+
"url": "https://formidable.com/open-source/urql/",
62+
"npm": "urql",
63+
"github": "FormidableLabs/urql"
64+
},
65+
{
66+
"name": "graphqurl",
67+
"description": "curl for GraphQL with autocomplete, subscriptions and GraphiQL. Also a dead-simple universal javascript GraphQL client.",
68+
"url": "https://github.com/hasura/graphqurl",
69+
"npm": "graphqurl",
70+
"github": "hasura/graphqurl"
71+
}
72+
]

data/js-server-libraries.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"name": "GraphQL.js",
4+
"description": "The reference implementation of the GraphQL specification, designed for running GraphQL in a Node.js environment.",
5+
"howto": "To run a `GraphQL.js` hello world script from the command line:\n\n```bash\nnpm install graphql\n```\n\nThen run `node hello.js` with this code in `hello.js`:\n\n```js\nvar { graphql, buildSchema } = require('graphql');\n\nvar schema = buildSchema(`\n type Query {\n hello: String\n }\n`);\n\nvar root = { hello: () => 'Hello world!' };\n\ngraphql(schema, '{ hello }', root).then((response) => {\n console.log(response);\n});\n```",
6+
"url": "/graphql-js/",
7+
"npm": "graphql",
8+
"github": "graphql/graphql-js"
9+
},
10+
{
11+
"name": "Express GraphQL",
12+
"description": "The reference implementation of a GraphQL API server over an Express webserver. You can use this to run GraphQL in conjunction with a regular Express webserver, or as a standalone GraphQL server.",
13+
"howto": "To run an `express-graphql` hello world server:\n\n```bash\nnpm install express express-graphql graphql\n```\n\nThen run `node server.js` with this code in `server.js`:\n\n```js\nvar express = require('express');\nvar { graphqlHTTP } = require('express-graphql');\nvar { buildSchema } = require('graphql');\n\nvar schema = buildSchema(`\n type Query {\n hello: String\n }\n`);\n\nvar root = { hello: () => 'Hello world!' };\n\nvar app = express();\napp.use('/graphql', graphqlHTTP({\n schema: schema,\n rootValue: root,\n graphiql: true,\n}));\napp.listen(4000, () => console.log('Now browse to localhost:4000/graphql'));\n```",
14+
"url": "/graphql-js/running-an-express-graphql-server/",
15+
"npm": "express-graphql",
16+
"github": "graphql/express-graphql"
17+
},
18+
{
19+
"name": "Apollo Server",
20+
"description": "A set of GraphQL server packages from Apollo that work with various Node.js HTTP frameworks (Express, Connect, Hapi, Koa etc).",
21+
"howto": "To run a hello world server with apollo-server-express:\n\n```bash\nnpm install apollo-server-express express \n```\n\nThen run `node server.js` with this code in `server.js`:\n\n```js\nconst express = require('express');\nconst { ApolloServer, gql } = require('apollo-server-express');\n\nconst typeDefs = gql`\n type Query {\n hello: String\n }\n`;\n\nconst resolvers = {\n Query: {\n hello: () => 'Hello world!',\n },\n};\n\nconst server = new ApolloServer({ typeDefs, resolvers });\n\nconst app = express();\nserver.applyMiddleware({ app });\n\napp.listen({ port: 4000 }, () =>\n console.log('Now browse to http://localhost:4000' + server.graphqlPath)\n);\n```\n\nApollo Server also supports all Node.js HTTP server frameworks: Express, Connect, HAPI, Koa and NestJs.",
22+
"url": "https://www.apollographql.com/docs/apollo-server/",
23+
"npm": "apollo-server-express",
24+
"github": "apollographql/apollo-server"
25+
}
26+
]

data/tools.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
[
2+
{
3+
"name": "GraphiQL",
4+
"description": "An interactive in-browser GraphQL IDE.",
5+
"url": "https://github.com/graphql/graphiql",
6+
"npm": "graphiql",
7+
"github": "graphql/graphiql"
8+
},
9+
{
10+
"name": "libgraphqlparser",
11+
"description": "A GraphQL query language parser in C++ with C and C++ APIs.",
12+
"url": "https://github.com/graphql/libgraphqlparser",
13+
"github": "graphql/libgraphqlparser"
14+
},
15+
{
16+
"name": "GraphQL Language Service",
17+
"description": "An interface for building GraphQL language services for IDEs (diagnostics, autocomplete etc).",
18+
"url": "https://github.com/graphql/graphql-language-service",
19+
"npm": "graphql-language-service",
20+
"github": "graphql/graphql-language-service"
21+
},
22+
{
23+
"name": "quicktype",
24+
"description": "Generate types for GraphQL queries in TypeScript, Swift, golang, C#, C++, and more.",
25+
"url": "https://quicktype.io/",
26+
"npm": "quicktype",
27+
"github": "quicktype/quicktype"
28+
},
29+
{
30+
"name": "GraphQL-ESLint",
31+
"description": "GraphQL-ESLint integrates GraphQL AST in the ESLint core (as a parser).",
32+
"url": "https://github.com/dotansimha/graphql-eslint/",
33+
"npm": "@graphql-eslint/eslint-plugin",
34+
"github": "dotansimha/graphql-eslint/"
35+
},
36+
{
37+
"name": "GraphQL Modules",
38+
"description": "GraphQL Modules lets you separate your backend implementation to small, reusable, easy-to-implement and easy-to-test pieces.",
39+
"url": "https://graphql-modules.com",
40+
"npm": "graphql-modules",
41+
"github": "Urigo/graphql-modules"
42+
},
43+
{
44+
"name": "GraphQL Tools",
45+
"description": "A set of utils for faster development of GraphQL tools (Schema and documents loading, Schema merging and more).",
46+
"url": "https://graphql-tools.com",
47+
"npm": "graphql-tools",
48+
"github": "ardatan/graphql-tools"
49+
},
50+
{
51+
"name": "GraphQL Config",
52+
"description": "One configuration for all your GraphQL tools (supported by most tools, editors & IDEs).",
53+
"url": "https://graphql-config.com",
54+
"npm": "graphql-config",
55+
"github": "kamilkisiela/graphql-config"
56+
},
57+
{
58+
"name": "GraphQL Mesh",
59+
"description": "GraphQL Mesh allows you to use GraphQL query language to access data in remote APIs that don't run GraphQL (and also ones that do run GraphQL). It can be used as a gateway to other services, or run as a local GraphQL schema that aggregates data from remote APIs.",
60+
"url": "https://graphql-mesh.com",
61+
"npm": "@graphql-mesh/cli",
62+
"github": "Urigo/graphql-mesh"
63+
},
64+
{
65+
"name": "GraphQL Code Generator",
66+
"description": "GraphQL code generator with flexible support for custom plugins and templates like Typescript (frontend and backend), React Hooks, resolvers signatures and more.",
67+
"url": "https://graphql-code-generator.com",
68+
"npm": "@graphql-codegen/cli",
69+
"github": "dotansimha/graphql-code-generator"
70+
},
71+
{
72+
"name": "GraphQL CLI",
73+
"description": "A command line tool for common GraphQL development workflows.",
74+
"url": "https://graphql-cli.com",
75+
"npm": "graphql-cli",
76+
"github": "Urigo/graphql-cli"
77+
},
78+
{
79+
"name": "GraphQL Inspector",
80+
"description": "Compare schemas, validate documents, find breaking changes, find similar types, schema coverage, and more.",
81+
"url": "https://graphql-inspector.com/",
82+
"npm": "@graphql-inspector/cli",
83+
"github": "kamilkisiela/graphql-inspector"
84+
},
85+
{
86+
"name": "GraphQL Scalars",
87+
"description": "A library of custom GraphQL scalar types for creating precise, type-safe GraphQL schemas.",
88+
"url": "https://github.com/Urigo/graphql-scalars",
89+
"npm": "graphql-scalars",
90+
"github": "Urigo/graphql-scalars"
91+
},
92+
{
93+
"name": "SOFA",
94+
"description": "Generate REST API from your GraphQL API.",
95+
"url": "https://sofa-api.com/",
96+
"npm": "sofa-api",
97+
"github": "Urigo/SOFA"
98+
}
99+
]

gatsby-node.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
const path = require("path")
2+
const { readFileSync } = require("fs")
3+
const sortLibs = require("./scripts/sort-libraries")
24

35
exports.onCreatePage = async ({ page, actions }) => {
46
const { createPage, deletePage } = actions
57
deletePage(page)
8+
let context = {
9+
...page.context,
10+
sourcePath: path.relative(__dirname, page.componentPath),
11+
}
12+
if (page.path === "/code" || page.path === "/code/") {
13+
const [jsGraphQLClients, jsServerLibraries, tools] = await Promise.all([
14+
sortLibs(
15+
JSON.parse(readFileSync("./data/js-graphql-clients.json", "utf8"))
16+
),
17+
sortLibs(
18+
JSON.parse(readFileSync("./data/js-server-libraries.json", "utf8"))
19+
),
20+
sortLibs(JSON.parse(readFileSync("./data/tools.json", "utf8"))),
21+
])
22+
23+
context = {
24+
...context,
25+
jsGraphQLClients,
26+
jsServerLibraries,
27+
tools,
28+
}
29+
}
630
createPage({
731
...page,
8-
context: {
9-
...page.context,
10-
sourcePath: path.relative(__dirname, page.componentPath),
11-
},
32+
context,
1233
})
1334
}
1435

scripts/sort-libraries.js

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
const fetch = require(`node-fetch`)
2+
3+
const getGitHubStats = async githubRepo => {
4+
const [owner, repoName] = githubRepo.split("/")
5+
const accessToken = process.env.GITHUB_ACCESS_TOKEN;
6+
if (!accessToken) {
7+
throw new Error(`You must have GITHUB_ACCESS_TOKEN env variable defined!`);
8+
}
9+
const query = /* GraphQL */ `
10+
fragment defaultBranchRef on Ref {
11+
target {
12+
... on Commit {
13+
history(since: $since) {
14+
edges {
15+
node {
16+
author {
17+
name
18+
}
19+
pushedDate
20+
}
21+
}
22+
}
23+
}
24+
}
25+
}
26+
query($owner: String!, $repoName: String!, $since: GitTimestamp!) {
27+
repositoryOwner(login: $owner) {
28+
repository(name: $repoName) {
29+
mainRef: ref(qualifiedName: "main") {
30+
...defaultBranchRef
31+
}
32+
sourceRef: ref(qualifiedName: "source") {
33+
...defaultBranchRef
34+
}
35+
masterRef: ref(qualifiedName: "master") {
36+
...defaultBranchRef
37+
}
38+
stargazers {
39+
totalCount
40+
}
41+
updatedAt
42+
forkCount
43+
pullRequests {
44+
totalCount
45+
}
46+
description
47+
}
48+
}
49+
}
50+
`
51+
const lastMonth = new Date();
52+
lastMonth.setMonth(lastMonth.getMonth() - 1);
53+
const response = await fetch("https://api.github.com/graphql", {
54+
method: "POST",
55+
body: JSON.stringify({
56+
query,
57+
variables: { owner, repoName, since: lastMonth },
58+
}),
59+
headers: {
60+
Authorization: `Bearer ${accessToken}`,
61+
"Content-Type": "application/json",
62+
},
63+
})
64+
const responseJson = await response.json()
65+
const repo = responseJson.data.repositoryOwner.repository
66+
const stars = repo.stargazers.totalCount
67+
const commitHistory = (repo.mainRef || repo.sourceRef || repo.masterRef)
68+
.target.history.edges
69+
let commitCount = 0, daysWithCommitSet = new Set(), finalUpdatedTime;
70+
commitHistory.forEach(commit => {
71+
if (!commit.node.author.name.match(/bot/i)) {
72+
commitCount++
73+
daysWithCommitSet.add(new Date(commit.node.pushedDate).getDate())
74+
}
75+
})
76+
return {
77+
commitCount,
78+
daysWithCommit: daysWithCommitSet.size,
79+
stars,
80+
}
81+
}
82+
83+
const getNpmStats = async packageName => {
84+
const response = await fetch(
85+
`https://api.npmjs.org/downloads/point/last-week/${encodeURIComponent(
86+
packageName
87+
)}`
88+
)
89+
const responseJson = await response.json()
90+
const downloadCount = responseJson.downloads
91+
return { downloadCount }
92+
}
93+
94+
const sortLibs = async libs => {
95+
const libsWithScores = await Promise.all(
96+
libs.map(async lib => {
97+
const [npmStats = {}, githubStats = {}] = await Promise.all([
98+
lib.npm && getNpmStats(lib.npm),
99+
lib.github && getGitHubStats(lib.github),
100+
])
101+
return {
102+
...lib,
103+
...npmStats,
104+
...githubStats,
105+
}
106+
})
107+
)
108+
return libsWithScores.sort((a, b) => {
109+
let aScore = 0,
110+
bScore = 0
111+
if (a.npm && b.npm) {
112+
if (a.downloadCount > b.downloadCount) {
113+
aScore += 40;
114+
} else if (b.downloadCount > a.downloadCount) {
115+
bScore += 40;
116+
}
117+
}
118+
if (a.github && b.github) {
119+
if (a.daysWithCommit > b.daysWithCommit) {
120+
aScore += 20
121+
} else if (a.daysWithCommit < b.daysWithCommit) {
122+
bScore += 20
123+
}
124+
if (a.commitCount > b.commitCount) {
125+
aScore += 20;
126+
} else if (a.commitCount < b.commitCount) {
127+
bScore += 20;
128+
}
129+
if (a.stars > b.stars) {
130+
aScore += 30;
131+
} else if (a.stars < b.stars) {
132+
bScore += 30;
133+
}
134+
}
135+
if (bScore > aScore) {
136+
return 1
137+
} else if (bScore < aScore) {
138+
return -1
139+
}
140+
return 0
141+
})
142+
}
143+
144+
module.exports = sortLibs

0 commit comments

Comments
 (0)