1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.GraphQLUpload = void 0;
|
4 | const Upload_1 = require("./Upload");
|
5 | const graphql_1 = require("graphql");
|
6 | /**
|
7 | * A GraphQL `Upload` scalar that can be used in a
|
8 | * [`GraphQLSchema`](https://graphql.org/graphql-js/type/#graphqlschema).
|
9 | * It's value in resolvers is a promise that resolves
|
10 | * [file upload details]{@link FileUpload} for processing and storage.
|
11 | * @example <caption>Ways to `import`.</caption>
|
12 | * ```js
|
13 | * import { GraphQLUpload } from 'graphql-upload-ts';
|
14 | * ```
|
15 | *
|
16 | * ```js
|
17 | * import GraphQLUpload from 'graphql-upload-ts/dist/GraphQLUpload.js';
|
18 | * ```
|
19 | * @example <caption>Ways to `require`.</caption>
|
20 | * ```js
|
21 | * const { GraphQLUpload } = require('graphql-upload-ts');
|
22 | * ```
|
23 | *
|
24 | * ```js
|
25 | * const GraphQLUpload = require('graphql-upload-ts/dist/GraphQLUpload');
|
26 | * ```
|
27 | * @example <caption>Setup for a schema built with [`makeExecutableSchema`](https://apollographql.com/docs/graphql-tools/generate-schema#makeExecutableSchema).</caption>
|
28 | * ```js
|
29 | * const { makeExecutableSchema } = require('graphql-tools');
|
30 | * const { GraphQLUpload } = require('graphql-upload-ts');
|
31 | *
|
32 | * const schema = makeExecutableSchema({
|
33 | * typeDefs: /* GraphQL *\/ `
|
34 | * scalar Upload
|
35 | * `,
|
36 | * resolvers: {
|
37 | * Upload: GraphQLUpload,
|
38 | * },
|
39 | * });
|
40 | * ```
|
41 | * @example <caption>A manually constructed schema with an image upload mutation.</caption>
|
42 | * ```js
|
43 | * const {
|
44 | * GraphQLSchema,
|
45 | * GraphQLObjectType,
|
46 | * GraphQLBoolean,
|
47 | * } = require('graphql');
|
48 | * const { GraphQLUpload } = require('graphql-upload-ts');
|
49 | *
|
50 | * const schema = new GraphQLSchema({
|
51 | * mutation: new GraphQLObjectType({
|
52 | * name: 'Mutation',
|
53 | * fields: {
|
54 | * uploadImage: {
|
55 | * description: 'Uploads an image.',
|
56 | * type: GraphQLBoolean,
|
57 | * args: {
|
58 | * image: {
|
59 | * description: 'Image file.',
|
60 | * type: GraphQLUpload,
|
61 | * },
|
62 | * },
|
63 | * async resolve(parent, { image }) {
|
64 | * const { filename, fieldName, mimetype, createReadStream } = await image;
|
65 | * const stream = createReadStream();
|
66 | * // Promisify the stream and store the file, then…
|
67 | * return true;
|
68 | * },
|
69 | * },
|
70 | * },
|
71 | * }),
|
72 | * });
|
73 | * ```
|
74 | */
|
75 | exports.GraphQLUpload = new graphql_1.GraphQLScalarType({
|
76 | name: 'Upload',
|
77 | description: 'The `Upload` scalar type represents a file upload.',
|
78 | parseValue(value) {
|
79 | if (value instanceof Upload_1.Upload)
|
80 | return value.promise;
|
81 | throw new graphql_1.GraphQLError('Upload value invalid.');
|
82 | },
|
83 | parseLiteral(node) {
|
84 | throw new graphql_1.GraphQLError('Upload literal unsupported.', { nodes: node });
|
85 | },
|
86 | serialize() {
|
87 | throw new graphql_1.GraphQLError('Upload serialization unsupported.');
|
88 | },
|
89 | });
|
90 | //# sourceMappingURL=GraphQLUpload.js.map |
\ | No newline at end of file |