Skip to content

Commit

Permalink
Update graphql-upload to 15.0.2 (keystonejs#7803)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored Aug 17, 2022
1 parent c0165f3 commit a711c46
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 138 deletions.
5 changes: 0 additions & 5 deletions .changeset/chatty-needles-eat.md

This file was deleted.

6 changes: 6 additions & 0 deletions .changeset/fast-pens-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-6/cloudinary': patch
'@keystone-6/core': patch
---

Updates `graphql-upload` to `15.0.2`
2 changes: 1 addition & 1 deletion packages/cloudinary/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"@types/react": "^18.0.9",
"cloudinary": "^1.27.1",
"cuid": "^2.1.8",
"graphql-upload": "^13.0.0",
"react": "^18.1.0"
},
"peerDependencies": {
"@keystone-6/core": "^2.1.0"
},
"devDependencies": {
"@keystone-6/core": "^2.1.0",
"graphql-upload": "^15.0.2",
"mime": "^3.0.0"
},
"engines": {
Expand Down
8 changes: 4 additions & 4 deletions packages/cloudinary/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
jsonFieldTypePolyfilledForSQLite,
} from '@keystone-6/core/types';
import { graphql } from '@keystone-6/core';
import { FileUpload } from 'graphql-upload';
import cuid from 'cuid';
import cloudinary from 'cloudinary';
import { CloudinaryAdapter } from './cloudinary';
Expand Down Expand Up @@ -116,8 +115,9 @@ export const cloudinaryImage =
throw Error("isIndexed: 'unique' is not a supported option for field type cloudinaryImage");
}
const adapter = new CloudinaryAdapter(cloudinary);
const inputArg = graphql.arg({ type: graphql.Upload });
const resolveInput = async (
uploadData: Promise<FileUpload> | undefined | null
uploadData: graphql.InferValueFromArg<typeof inputArg>
): Promise<StoredFile | undefined | null | 'DbNull'> => {
if (uploadData === null) {
return meta.provider === 'postgresql' || meta.provider === 'mysql' ? 'DbNull' : null;
Expand Down Expand Up @@ -149,8 +149,8 @@ export const cloudinaryImage =
{
...config,
input: {
create: { arg: graphql.arg({ type: graphql.Upload }), resolve: resolveInput },
update: { arg: graphql.arg({ type: graphql.Upload }), resolve: resolveInput },
create: { arg: inputArg, resolve: resolveInput },
update: { arg: inputArg, resolve: resolveInput },
},
output: graphql.field({
type: outputType,
Expand Down
5 changes: 3 additions & 2 deletions packages/cloudinary/src/test-fixtures.skip.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';
import mime from 'mime';
import { FileUpload, Upload } from 'graphql-upload';
// @ts-ignore
import Upload from 'graphql-upload/Upload.js';
import cloudinary from 'cloudinary';
import { cloudinaryImage } from './index';

Expand All @@ -22,7 +23,7 @@ const prepareFile = (_filePath: string) => {
mimetype: mime.getType(filePath),
encoding: 'utf-8',
});
return upload as Upload & { file: FileUpload };
return upload;
};

// Configurations
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"@types/cookie": "^0.5.0",
"@types/express": "^4.17.13",
"@types/fs-extra": "^9.0.13",
"@types/graphql-upload": "8.0.7",
"@types/inflection": "^1.13.0",
"@types/node-fetch": "^2.5.12",
"@types/pluralize": "^0.0.29",
Expand Down Expand Up @@ -98,7 +97,7 @@
"fs-extra": "^10.0.0",
"graphql": "^15.8.0",
"graphql-type-json": "^0.3.2",
"graphql-upload": "^13.0.0",
"graphql-upload": "^15.0.2",
"image-size": "^1.0.0",
"image-type": "^4.1.0",
"inflection": "^1.13.1",
Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/fields/types/file/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FileUpload } from 'graphql-upload';
import {
fieldType,
FieldTypeFunc,
Expand All @@ -21,7 +20,7 @@ const FileFieldInput = graphql.inputObject({
},
});

type FileFieldInputType = undefined | null | { upload: Promise<FileUpload> };
const inputArg = graphql.arg({ type: FileFieldInput });

const FileFieldOutput = graphql.object<FileMetadata & { storage: string }>()({
name: 'FileFieldOutput',
Expand All @@ -37,7 +36,11 @@ const FileFieldOutput = graphql.object<FileMetadata & { storage: string }>()({
},
});

async function inputResolver(storage: string, data: FileFieldInputType, context: KeystoneContext) {
async function inputResolver(
storage: string,
data: graphql.InferValueFromArg<typeof inputArg>,
context: KeystoneContext
) {
if (data === null || data === undefined) {
return { filename: data, filesize: data };
}
Expand Down Expand Up @@ -95,11 +98,11 @@ export const file =
},
input: {
create: {
arg: graphql.arg({ type: FileFieldInput }),
arg: inputArg,
resolve: (data, context) => inputResolver(config.storage, data, context),
},
update: {
arg: graphql.arg({ type: FileFieldInput }),
arg: inputArg,
resolve: (data, context) => inputResolver(config.storage, data, context),
},
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/fields/types/file/tests/test-fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'path';
import os from 'os';
import fs from 'fs-extra';
import { Upload } from 'graphql-upload';
// @ts-ignore
import Upload from 'graphql-upload/Upload.js';
import mime from 'mime';
import { file } from '..';
import { KeystoneConfig } from '../../../../types/config';
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/fields/types/image/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FileUpload } from 'graphql-upload';
import {
BaseListTypeInfo,
fieldType,
Expand Down Expand Up @@ -28,6 +27,8 @@ const ImageFieldInput = graphql.inputObject({
},
});

const inputArg = graphql.arg({ type: ImageFieldInput });

const ImageFieldOutput = graphql.object<ImageData & { storage: string }>()({
name: 'ImageFieldOutput',
fields: {
Expand All @@ -45,9 +46,11 @@ const ImageFieldOutput = graphql.object<ImageData & { storage: string }>()({
},
});

type ImageFieldInputType = undefined | null | { upload: Promise<FileUpload> };

async function inputResolver(storage: string, data: ImageFieldInputType, context: KeystoneContext) {
async function inputResolver(
storage: string,
data: graphql.InferValueFromArg<typeof inputArg>,
context: KeystoneContext
) {
if (data === null || data === undefined) {
return { extension: data, filesize: data, height: data, id: data, width: data };
}
Expand Down Expand Up @@ -118,11 +121,11 @@ export const image =
},
input: {
create: {
arg: graphql.arg({ type: ImageFieldInput }),
arg: inputArg,
resolve: (data, context) => inputResolver(config.storage, data, context),
},
update: {
arg: graphql.arg({ type: ImageFieldInput }),
arg: inputArg,
resolve: (data, context) => inputResolver(config.storage, data, context),
},
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/fields/types/image/tests/test-fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import path from 'path';
import os from 'os';
import fs from 'fs-extra';
import { Upload } from 'graphql-upload';
// @ts-ignore
import Upload from 'graphql-upload/Upload.js';
import mime from 'mime';
import { KeystoneConfig } from '../../../../types';
import { image } from '..';
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/lib/server/createExpressServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { createServer, IncomingMessage, Server, ServerResponse } from 'http';
import cors, { CorsOptions } from 'cors';
import express from 'express';
import { GraphQLSchema } from 'graphql';
import { graphqlUploadExpress } from 'graphql-upload';
// @ts-ignore
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';
import { ApolloServer } from 'apollo-server-express';
import type { KeystoneConfig, CreateContext, SessionStrategy, GraphQLConfig } from '../../types';
import { createSessionContext } from '../../session';
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/types/schema/graphql-ts-schema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { ReadStream } from 'fs';
import * as graphqlTsSchema from '@graphql-ts/schema';
import { GraphQLJSON } from 'graphql-type-json';
// this is imported from a specific path so that we don't import busboy here because webpack doesn't like bundling it
// @ts-ignore
import GraphQLUpload from 'graphql-upload/public/GraphQLUpload.js';
import type { FileUpload } from 'graphql-upload';
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
import { GraphQLError, GraphQLScalarType } from 'graphql';
import { Decimal as DecimalValue } from 'decimal.js';
import { KeystoneContext } from '../context';
Expand Down Expand Up @@ -45,6 +44,14 @@ export { field, fields, interface, interfaceField, object, union } from './schem
export type Context = KeystoneContext;

export const JSON = graphqlTsSchema.graphql.scalar<JSONValue>(GraphQLJSON);

type FileUpload = {
filename: string;
mimetype: string;
encoding: string;
createReadStream(): ReadStream;
};

export const Upload = graphqlTsSchema.graphql.scalar<Promise<FileUpload>>(GraphQLUpload);

// - Decimal.js throws on invalid inputs
Expand Down
3 changes: 2 additions & 1 deletion tests/api-tests/fields/image-file-crud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { createHash } from 'crypto';
import os from 'os';
import fs from 'fs-extra';
import fetch from 'node-fetch';
import { Upload } from 'graphql-upload';
// @ts-ignore
import Upload from 'graphql-upload/Upload.js';
import mime from 'mime';
import { file, text, image } from '@keystone-6/core/fields';
import { list } from '@keystone-6/core';
Expand Down
2 changes: 1 addition & 1 deletion tests/api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"fs-extra": "^10.0.0",
"globby": "^11.0.4",
"graphql": "^15.8.0",
"graphql-upload": "^13.0.0",
"graphql-upload": "^15.0.2",
"memoize-one": "^6.0.0",
"mime": "^3.0.0",
"node-fetch": "^2.6.7",
Expand Down
Loading

0 comments on commit a711c46

Please sign in to comment.