webcomponents / webcomponents.org

Home of the web components community
https://www.webcomponents.org
Apache License 2.0
359 stars 95 forks source link

Add GraphQL endpoint #1343

Closed justinfagnani closed 1 year ago

justinfagnani commented 1 year ago

This adds a Koa server and /graphql endpoint to the catalog-server package.

The server is implemented with graphql-helix, which makes it very easy to parse a GraphQL request, execute it against a schema, and send the result. I chose this after koa-graphql seemed unmaintained and have been happy with it.

GraphQL execution is implemented with "resolvers" - objects that let the GraphQL system ask for objects and fields. There are resolvers based on type like PackageInfo, ReadablePackageInfo, PackageVersion, etc. Then field resolvers for sub-collections like ReadablePackageVersion.customElements. The resolvers use the Catalog interface to fetch results. Resolvers are combined with the parsed schema into a "executable schema" which graphql-helix uses to validate and perform the queries.

There is no access control, rate-limiting, etc., yet.

Fixes #1325