Skip to content
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

Update file info mutation #7691

Merged
merged 4 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/strapi-plugin-upload/config/schema.graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ const _ = require('lodash');
const { streamToBuffer } = require('../utils/file');

module.exports = {
definition: `
input FileInfoInput {
name: String
alternativeText: String
caption: String
}
`,
mutation: `
upload(refId: ID, ref: String, field: String, source: String, file: Upload!): UploadFile!
multipleUpload(refId: ID, ref: String, field: String, source: String, files: [Upload]!): [UploadFile]!
updateFileInfo(id: ID!, info: FileInfoInput!): UploadFile!
`,
resolver: {
Query: {
Expand Down Expand Up @@ -42,6 +50,13 @@ module.exports = {
return Promise.all(files.map(file => uploadService.uploadFileAndPersist(file)));
},
},
updateFileInfo: {
description: 'Update file information',
resolverOf: 'plugins::upload.upload.upload',
resolver: async (obj, { id, info }) => {
return await strapi.plugins.upload.services.upload.updateFileInfo(id, info);
},
},
},
},
};
Expand Down
43 changes: 43 additions & 0 deletions packages/strapi-plugin-upload/test/graphqlUpload.test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const setConfigOptions = assign => {
});
};

const data = {};

describe('Upload plugin end to end tests', () => {
beforeAll(async () => {
const token = await registerAndLogin();
Expand Down Expand Up @@ -79,6 +81,8 @@ describe('Upload plugin end to end tests', () => {
},
},
});

data.file = res.body.data.upload;
});

test('Upload multiple files', async () => {
Expand Down Expand Up @@ -128,4 +132,43 @@ describe('Upload plugin end to end tests', () => {
},
});
});

test('Update file information', async () => {
const res = await rq({
url: '/graphql',
method: 'POST',
body: {
query: /* GraphQL */ `
mutation updateFileInfo($id: ID!, $info: FileInfoInput!) {
updateFileInfo(id: $id, info: $info) {
id
name
alternativeText
caption
}
}
`,
variables: {
id: data.file.id,
info: {
name: 'test name',
alternativeText: 'alternative text test',
caption: 'caption test',
},
},
},
});

expect(res.statusCode).toBe(200);
expect(res.body).toMatchObject({
data: {
updateFileInfo: {
id: data.file.id,
name: 'test name',
alternativeText: 'alternative text test',
caption: 'caption test',
},
},
});
});
});