Skip to content

feat: Switch from Yoga v2 to Apollo Server v4 #8727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"lodash": "4.17.21",
"lru-cache": "9.1.1",
"mime": "3.0.0",
"mime-types": "2.1.35",
Copy link
Member

@mtrezza mtrezza Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have mime, it seems that it's similar to mime-types. I think if possible we should decide for one of the two if they provide the same functionality.

"mongodb": "4.10.0",
"mustache": "4.2.0",
"otpauth": "9.1.2",
Expand Down
54 changes: 54 additions & 0 deletions spec/ParseGraphQLServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9549,6 +9549,60 @@ describe('ParseGraphQLServer', () => {
}
});

it('should support files and add extension from mimetype', async () => {
try {
parseServer = await global.reconfigureServer({
publicServerURL: 'http://localhost:13377/parse',
});

const body = new FormData();
body.append(
'operations',
JSON.stringify({
query: `
mutation CreateFile($input: CreateFileInput!) {
createFile(input: $input) {
fileInfo {
name
url
}
}
}
`,
variables: {
input: {
upload: null,
},
},
})
);
body.append('map', JSON.stringify({ 1: ['variables.input.upload'] }));
body.append('1', 'My File Content', {
// No extension, the system should add it from mimetype
filename: 'myFileName',
contentType: 'text/plain',
});

const res = await fetch('http://localhost:13377/graphql', {
method: 'POST',
headers,
body,
});

expect(res.status).toEqual(200);

const result = JSON.parse(await res.text());
expect(result.data.createFile.fileInfo.name).toEqual(
jasmine.stringMatching(/_myFileName.txt$/)
);
expect(result.data.createFile.fileInfo.url).toEqual(
jasmine.stringMatching(/_myFileName.txt$/)
);
} catch (e) {
handleError(e);
}
});

it('should not upload if file is too large', async () => {
const body = new FormData();
body.append(
Expand Down
7 changes: 5 additions & 2 deletions src/GraphQL/loaders/filesMutations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GraphQLNonNull } from 'graphql';
import { request } from 'http';
import { extension } from 'mime-types';
import { mutationWithClientMutationId } from 'graphql-relay';
import Parse from 'parse/node';
import * as defaultGraphQLTypes from './defaultGraphQLTypes';
Expand All @@ -10,7 +11,7 @@ import logger from '../../logger';
// We do not call directly createFile from the Parse Server
// to leverage the standard file upload mechanism
const handleUpload = async (upload, config) => {
const { createReadStream, filename } = await upload;
const { createReadStream, filename, mimetype } = await upload;
const headers = { ...config.headers };
delete headers['accept-encoding'];
delete headers['accept'];
Expand All @@ -19,13 +20,15 @@ const handleUpload = async (upload, config) => {
delete headers['content-length'];
const stream = createReadStream();
try {
const ext = extension(mimetype);
const fullFileName = filename.endsWith(`.${ext}`) ? filename : `${filename}.${ext}`;
const serverUrl = new URL(config.serverURL);
const fileInfo = await new Promise((resolve, reject) => {
const req = request(
{
hostname: serverUrl.hostname,
port: serverUrl.port,
path: `${serverUrl.pathname}/files/${filename}`,
path: `${serverUrl.pathname}/files/${fullFileName}`,
method: 'POST',
headers,
},
Expand Down