diff --git a/examples/file-upload/__integration-tests__/file-upload.spec.ts b/examples/file-upload/__integration-tests__/file-upload.spec.ts index 8c6f7b4161..06a759d780 100644 --- a/examples/file-upload/__integration-tests__/file-upload.spec.ts +++ b/examples/file-upload/__integration-tests__/file-upload.spec.ts @@ -49,15 +49,7 @@ describe('graphql-auth example integration', () => { }) it('should save file', async () => { - const sourceFilePath = path.join( - __dirname, - '..', - '..', - '..', - 'website', - 'public', - 'logo.png', - ) + const sourceFilePath = path.join(__dirname, 'fixtures', 'image.jpg') const sourceMd5 = await md5File(sourceFilePath) const formData = new FormData() @@ -77,7 +69,7 @@ describe('graphql-auth example integration', () => { new File( [await fs.promises.readFile(sourceFilePath)], path.basename(sourceFilePath), - { type: 'image/png' }, + { type: 'image/jpg' }, ), ) @@ -92,7 +84,7 @@ describe('graphql-auth example integration', () => { saveFile: true, }) - const targetFilePath = path.join(__dirname, '..', 'logo.png') + const targetFilePath = path.join(__dirname, '..', 'image.jpg') await fs.promises.stat(targetFilePath) const targetMd5 = await md5File(targetFilePath) expect(targetMd5).toEqual(sourceMd5) diff --git a/examples/file-upload/__integration-tests__/fixtures/image.jpg b/examples/file-upload/__integration-tests__/fixtures/image.jpg new file mode 100644 index 0000000000..9d7c8475a1 Binary files /dev/null and b/examples/file-upload/__integration-tests__/fixtures/image.jpg differ diff --git a/examples/file-upload/yoga.ts b/examples/file-upload/yoga.ts index 4ce024b82a..40ab33578b 100644 --- a/examples/file-upload/yoga.ts +++ b/examples/file-upload/yoga.ts @@ -25,10 +25,10 @@ export const yoga = createYoga({ }, saveFile: async (_, { file }: { file: File }) => { try { - const fileStream = file.stream() + const fileArrayBuffer = await file.arrayBuffer() await fs.promises.writeFile( path.join(__dirname, file.name), - fileStream, + Buffer.from(fileArrayBuffer), ) } catch (e) { return false diff --git a/packages/graphql-yoga/__integration-tests__/incremental-delivery.spec.ts b/packages/graphql-yoga/__integration-tests__/incremental-delivery.spec.ts index b7d0ae4b33..2efff2ec3c 100644 --- a/packages/graphql-yoga/__integration-tests__/incremental-delivery.spec.ts +++ b/packages/graphql-yoga/__integration-tests__/incremental-delivery.spec.ts @@ -19,7 +19,6 @@ describe('incremental delivery', () => { const fakeIterator: AsyncIterableIterator = { [Symbol.asyncIterator]: () => fakeIterator, - // eslint-disable-next-line @typescript-eslint/require-await async next() { counter++ return { diff --git a/website/src/pages/v2/features/file-uploads.mdx b/website/src/pages/v2/features/file-uploads.mdx index 0b339c9585..bc20e26aa4 100644 --- a/website/src/pages/v2/features/file-uploads.mdx +++ b/website/src/pages/v2/features/file-uploads.mdx @@ -23,7 +23,7 @@ You only need to add a scalar type definition for file uploads in your schema. T Let's use `File` in this example: ```ts filename="file-upload-example.ts" -import fs from 'node:fs/promises' +import fs from 'node:fs' import path from 'node:path' import { createServer } from '@graphql-yoga/node' @@ -57,8 +57,11 @@ const server = createServer({ }, async saveFile(_, { file }: { file: File }) { try { - const fileStream = file.stream() - await fs.writeFile(path.join(__dirname, file.name), fileStream) + const fileArrayBuffer = await file.arrayBuffer() + await fs.promises.writeFile( + path.join(__dirname, file.name), + Buffer.from(fileArrayBuffer) + ) return true } catch { return false