Skip to content

Commit 13fde60

Browse files
committed
Improve documentation.
1 parent a879382 commit 13fde60

3 files changed

Lines changed: 36 additions & 13 deletions

File tree

GraphQLUpload.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Upload from "./Upload.mjs";
1212
* value in resolvers is a promise that resolves
1313
* {@link FileUpload file upload details} for processing and storage.
1414
* @example
15-
* A schema built using
15+
* A schema built using the function
1616
* [`makeExecutableSchema`](https://www.graphql-tools.com/docs/api/modules/schema_src#makeexecutableschema)
1717
* from [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema):
1818
*
@@ -60,6 +60,14 @@ import Upload from "./Upload.mjs";
6060
* }),
6161
* });
6262
* ```
63+
* @example
64+
* In a [TypeScript](https://typescriptlang.org) module, how to import the type
65+
* for the {@link FileUpload file upload details} that the
66+
* {@linkcode GraphQLUpload} scalar resolver value promise resolves:
67+
*
68+
* ```ts
69+
* import type { FileUpload } from "graphql-upload/processRequest.mjs";
70+
* ```
6371
*/
6472
const GraphQLUpload = new GraphQLScalarType({
6573
name: "Upload",

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
### Patch
66

77
- Updated dev dependencies.
8+
- Improved JSDoc in the module `GraphQLUpload.mjs`.
9+
- Revamped the readme:
10+
- Removed the badges.
11+
- More detailed installation instructions.
12+
- Added information about TypeScript config and [optimal JavaScript module design](https://jaydenseric.com/blog/optimal-javascript-module-design).
813

914
## 16.0.1
1015

readme.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@
22

33
# graphql-upload
44

5-
[![npm version](https://badgen.net/npm/v/graphql-upload)](https://npm.im/graphql-upload) [![CI status](https://github.com/jaydenseric/graphql-upload/workflows/CI/badge.svg)](https://github.com/jaydenseric/graphql-upload/actions)
6-
75
Middleware and an [`Upload`](./GraphQLUpload.mjs) scalar to add support for [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec) (file uploads via queries and mutations) to various Node.js GraphQL servers.
86

7+
[Clients implementing the GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec#client) upload files as [`Upload`](./GraphQLUpload.mjs) scalar query or mutation variables. Their resolver values are promises that resolve file upload details for processing and storage. Files are typically streamed into cloud storage but may also be stored in the filesystem.
8+
99
## Installation
1010

11-
First, check if there are [GraphQL multipart request spec server implementations](https://github.com/jaydenseric/graphql-multipart-request-spec#server) (most for Node.js integrate [`graphql-upload`](https://npm.im/graphql-upload)) that are more suitable for your environment than a manual setup.
11+
> **Note**
12+
>
13+
> First, check if there are [GraphQL multipart request spec server implementations](https://github.com/jaydenseric/graphql-multipart-request-spec#server) (most for Node.js integrate [`graphql-upload`](https://npm.im/graphql-upload)) that are more suitable for your environment than a manual setup.
1214
13-
To install [`graphql-upload`](https://npm.im/graphql-upload) and the [`graphql`](https://npm.im/graphql) peer dependency with [npm](https://npmjs.com/get-npm), run:
15+
To install [`graphql-upload`](https://npm.im/graphql-upload) and its [`graphql`](https://npm.im/graphql) peer dependency with [npm](https://npmjs.com/get-npm), run:
1416

1517
```sh
1618
npm install graphql-upload graphql
1719
```
1820

19-
Use the [`graphqlUploadKoa`](./graphqlUploadKoa.mjs) or [`graphqlUploadExpress`](./graphqlUploadExpress.mjs) middleware just before GraphQL middleware. Alternatively, use [`processRequest`](./processRequest.mjs) to create custom middleware.
21+
Use the middleware [`graphqlUploadKoa`](./graphqlUploadKoa.mjs) or [`graphqlUploadExpress`](./graphqlUploadExpress.mjs) just before GraphQL middleware. Alternatively, use the function [`processRequest`](./processRequest.mjs) to create custom middleware.
2022

21-
A schema built with separate SDL and resolvers (e.g. using [`makeExecutableSchema`](https://www.graphql-tools.com/docs/api/modules/schema_src#makeexecutableschema) from [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema)) requires the [`Upload`](./GraphQLUpload.mjs) scalar to be setup.
23+
A schema built with separate SDL and resolvers (e.g. using the function [`makeExecutableSchema`](https://www.graphql-tools.com/docs/api/modules/schema_src#makeexecutableschema) from [`@graphql-tools/schema`](https://npm.im/@graphql-tools/schema)) requires the [`Upload`](./GraphQLUpload.mjs) scalar to be setup.
2224

23-
## Usage
25+
Then, the [`Upload`](./GraphQLUpload.mjs) scalar can be used for query or mutation arguments. For how to use the scalar value in resolvers, see the documentation in the module [`GraphQLUpload.mjs`](./GraphQLUpload.mjs).
2426

25-
[Clients implementing the GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec#client) upload files as [`Upload`](./GraphQLUpload.mjs) scalar query or mutation variables. Their resolver values are promises that resolve file upload details for processing and storage. Files are typically streamed into cloud storage but may also be stored in the filesystem.
27+
## Examples
2628

27-
See the [example API and client](https://github.com/jaydenseric/apollo-upload-examples).
29+
- [Apollo upload examples repo](https://github.com/jaydenseric/apollo-upload-examples); a full stack demo of file uploads via GraphQL mutations using [`apollo-server-koa`](https://npm.im/apollo-server-koa) and [`@apollo/client`](https://npm.im/@apollo/client).
2830

29-
### Tips
31+
## Tips
3032

3133
- The process must have both read and write access to the directory identified by [`os.tmpdir()`](https://nodejs.org/api/os.html#ostmpdir).
3234
- The device requires sufficient disk space to buffer the expected number of concurrent upload requests.
@@ -46,11 +48,19 @@ The [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-mult
4648

4749
## Requirements
4850

49-
- [Node.js](https://nodejs.org): `^14.17.0 || ^16.0.0 || >= 18.0.0`
51+
Supported runtime environments:
52+
53+
- [Node.js](https://nodejs.org) versions `^14.17.0 || ^16.0.0 || >= 18.0.0`.
54+
55+
Projects must configure [TypeScript](https://typescriptlang.org) to use types from the ECMAScript modules that have a `// @ts-check` comment:
56+
57+
- [`compilerOptions.allowJs`](https://typescriptlang.org/tsconfig#allowJs) should be `true`.
58+
- [`compilerOptions.maxNodeModuleJsDepth`](https://typescriptlang.org/tsconfig#maxNodeModuleJsDepth) should be reasonably large, e.g. `10`.
59+
- [`compilerOptions.module`](https://typescriptlang.org/tsconfig#module) should be `"node16"` or `"nodenext"`.
5060

5161
## Exports
5262

53-
These ECMAScript modules are published to [npm](https://npmjs.com) and exported via the [`package.json`](./package.json) `exports` field:
63+
The [npm](https://npmjs.com) package [`graphql-upload`](https://npm.im/graphql-upload) features [optimal JavaScript module design](https://jaydenseric.com/blog/optimal-javascript-module-design). It doesn’t have a main index module, so use deep imports from the ECMAScript modules that are exported via the [`package.json`](./package.json) field [`exports`](https://nodejs.org/api/packages.html#exports):
5464

5565
- [`GraphQLUpload.mjs`](./GraphQLUpload.mjs)
5666
- [`graphqlUploadExpress.mjs`](./graphqlUploadExpress.mjs)

0 commit comments

Comments
 (0)