-
Notifications
You must be signed in to change notification settings - Fork 7
/
gatsby-node.js
59 lines (56 loc) · 1.32 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { GraphQLInt, GraphQLString } from "gatsby/graphql";
import { createRemoteFileNode } from "gatsby-source-filesystem";
import { ImageFormatType } from "./types";
export const setFieldsOnGraphQLNodeType = ({ type }) => {
if (type.name === `SanityImageAsset`) {
return {
localFile: {
type: `File`,
args: {
width: {
type: GraphQLInt
},
format: {
type: ImageFormatType
},
height: {
type: GraphQLInt
},
fit: {
type: GraphQLString,
defaultValue: "crop"
}
}
}
};
}
// by default return empty object
return {};
};
export const createResolvers = ({
actions: { createNode },
cache,
createNodeId,
createResolvers,
store,
reporter
}) => {
const resolvers = {
SanityImageAsset: {
localFile: {
resolve: (source, { width, height, fit, format }) => {
const url = `${source.url}?fit=${fit}${format ? `&fm=${format}`: ''}${width ? `&w=${width}` : ''}${height ? `&h=${height}` : ''}`;
return createRemoteFileNode({
url,
store,
cache,
createNode,
createNodeId,
reporter
});
}
}
}
};
createResolvers(resolvers);
};