Skip to content

Commit 15fcfa8

Browse files
committed
refactor: rename images to exports so we can export css
1 parent 6f99f20 commit 15fcfa8

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

src/types/__tests__/file.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("File", () => {
3333
const query = `
3434
query {
3535
file(id: "${figmaFile}") {
36-
images {
36+
exports {
3737
id
3838
}
3939
}
@@ -43,15 +43,15 @@ describe("File", () => {
4343
const response = await graphql(schema, query, null, { fileId: figmaFile });
4444

4545
expect(response).toEqual({
46-
data: { file: { images: [{ id: "0:1" }] } },
46+
data: { file: { exports: [{ id: "0:1" }] } },
4747
});
4848
});
4949

5050
test("can get specific file images", async () => {
5151
const query = `
5252
query {
5353
file(id: "${figmaFile}") {
54-
images(params: { ids: ["1:6"]}) {
54+
exports(params: { ids: ["1:6"]}) {
5555
id
5656
}
5757
}
@@ -61,7 +61,7 @@ describe("File", () => {
6161
const response = await graphql(schema, query, null, { fileId: figmaFile });
6262

6363
expect(response).toEqual({
64-
data: { file: { images: [{ id: "1:6" }] } },
64+
data: { file: { exports: [{ id: "1:6" }] } },
6565
});
6666
});
6767

src/types/image.ts src/types/export.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ export const type = gql`
1010
svg
1111
}
1212
13+
enum ExportFormat {
14+
jpg
15+
png
16+
svg
17+
css
18+
}
19+
1320
input ImageParams {
1421
# A comma separated list of node IDs to render
1522
ids: [ID]
@@ -21,31 +28,31 @@ export const type = gql`
2128
format: ImageFormat
2229
}
2330
24-
input ImageNodeParams {
31+
input ExportParams {
2532
# A number between 0.01 and 4, the image scaling factor
2633
scale: Int
2734
2835
# A string enum for the image output format, can be "jpg", "png", or "svg"
29-
format: ImageFormat
36+
format: ExportFormat
3037
}
3138
32-
type Image {
39+
type ExportResult {
3340
id: String
34-
file: String
41+
output: String
3542
}
3643
3744
extend type Query {
3845
# Get just the image of a node id in a file
39-
images(id: ID!, params: ImageParams): [Image]
46+
exports(id: ID!, params: ImageParams): [ExportResult]
4047
}
4148
`;
4249

4350
export const resolvers = {
4451
Query: {
45-
images: async (root, { id, params }) => {
52+
exports: async (root, { id, params }) => {
4653
const imageParams = { ...defaultImageParams, ...params };
4754
const { images } = await loadImages(id, imageParams).then(data => data);
48-
return Object.entries(images).map(entry => ({ id: entry[0], file: entry[1] }));
55+
return Object.entries(images).map(entry => ({ id: entry[0], output: entry[1] }));
4956
},
5057
},
5158
};

src/types/file.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { gql } from "apollo-server-express";
22
import { loadFile, loadImages, loadComments } from "../utils/figma";
33
import { generateResolversForShortcuts, generateQueriesForShortcuts } from "../utils/shortcuts";
4-
import { defaultImageParams } from "./image";
4+
import { defaultImageParams } from "./export";
55

66
export const type = gql`
77
# Information about a file
@@ -19,7 +19,7 @@ export const type = gql`
1919
version: String
2020
2121
# Get images for the file
22-
images(params: ImageParams): [Image]
22+
exports(params: ImageParams): [ExportResult]
2323
2424
# Get comments for the file
2525
comments: [Comment]
@@ -38,10 +38,10 @@ export const resolvers = {
3838
file: (_, { id }) => loadFile(id).then(data => data),
3939
},
4040
File: {
41-
images: async ({ fileId }, { params }) => {
41+
exports: async ({ fileId }, { params }) => {
4242
const imageParams = { ...defaultImageParams, ...params };
4343
const { images } = await loadImages(fileId, imageParams);
44-
return Object.entries(images).map(entry => ({ id: entry[0], file: entry[1] }));
44+
return Object.entries(images).map(entry => ({ id: entry[0], output: entry[1] }));
4545
},
4646
comments: ({ fileId }) => loadComments(fileId).then(({ comments }) => comments),
4747
...generateResolversForShortcuts(),

src/types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as page from "./page";
44
import * as frame from "./frame";
55
import * as node from "./node";
66
import * as vector from "./vector";
7-
import * as image from "./image";
7+
import * as fileExport from "./export";
88
import * as comments from "./comments";
99
import * as projects from "./projects";
1010
import * as projectFiles from "./project-files";
@@ -21,7 +21,7 @@ const typePaths = [
2121
frame,
2222
node,
2323
vector,
24-
image,
24+
fileExport,
2525
comments,
2626
projects,
2727
projectFiles,

0 commit comments

Comments
 (0)