UNPKG

4.42 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _graphql = require("graphql");
9
10var _commonTags = require("common-tags");
11
12var _gatsbyCloudinary = require("@dylanvann/gatsby-cloudinary");
13
14var _default = ({
15 pathPrefix,
16 getNodeAndSavePathDependency,
17 reporter,
18 cloudinaryConfig
19}) => {
20 return {
21 type: new _graphql.GraphQLObjectType({
22 name: 'ImageCloudinaryFluid',
23 fields: {
24 width: {
25 type: _graphql.GraphQLFloat,
26 description: 'The original width of the media.'
27 },
28 height: {
29 type: _graphql.GraphQLFloat,
30 description: 'The original height of the media.'
31 },
32 // ----------------------------------------
33 // img
34 // ----------------------------------------
35 imgSrc: {
36 type: _graphql.GraphQLString,
37 description: _commonTags.oneLine`
38 src for the image.
39 `
40 },
41 imgSrcSet: {
42 type: _graphql.GraphQLString,
43 description: _commonTags.oneLine`
44 srcSet for the image.
45 `
46 },
47 imgWebPSrc: {
48 type: _graphql.GraphQLString,
49 description: _commonTags.oneLine`
50 src for the image (WebP).
51 `
52 },
53 imgWebPSrcSet: {
54 type: _graphql.GraphQLString,
55 description: _commonTags.oneLine`
56 srcSet for the image (WebP).
57 `
58 },
59 imgBase64: {
60 type: _graphql.GraphQLString,
61 description: _commonTags.oneLine`
62 A base64 version of the image.
63 `
64 },
65 // ----------------------------------------
66 // video
67 //
68 // no srcSet or base64
69 // as those do not make sense for videos
70 // ----------------------------------------
71 videoSrc: {
72 type: _graphql.GraphQLString,
73 description: _commonTags.oneLine`
74 src for the video.
75 `
76 },
77 // ----------------------------------------
78 // videoPoster
79 // ----------------------------------------
80 videoPosterSrc: {
81 type: _graphql.GraphQLString,
82 description: _commonTags.oneLine`
83 src for the poster.
84 `
85 },
86 videoPosterSrcSet: {
87 type: _graphql.GraphQLString,
88 description: _commonTags.oneLine`
89 srcSet for the poster.
90 `
91 },
92 videoPosterBase64: {
93 type: _graphql.GraphQLString,
94 description: _commonTags.oneLine`
95 A base64 version of the poster.
96 `
97 },
98 sizes: {
99 type: _graphql.GraphQLString
100 }
101 }
102 }),
103 args: {
104 maxWidth: {
105 type: _graphql.GraphQLInt,
106 description: 'The max width the media will be displayed at.',
107 defaultValue: 800
108 },
109 maxHeight: {
110 type: _graphql.GraphQLInt,
111 description: _commonTags.oneLine`
112 The max height the media will be displayed at.
113 You probably want to use maxWidth instead of this.
114 `
115 },
116 toImgFormat: {
117 type: _graphql.GraphQLString,
118 description: 'Format to convert img to.'
119 },
120 toVideoFormat: {
121 type: _graphql.GraphQLString,
122 description: 'Format to convert video to.'
123 },
124 toVideoPosterFormat: {
125 type: _graphql.GraphQLString,
126 description: 'Format to convert videoPoster to.'
127 }
128 },
129 resolve: async (image, fieldArgs, context) => {
130 try {
131 const file = getNodeAndSavePathDependency(image.parent, context.path);
132 const path = file.absolutePath;
133 const maxWidth = fieldArgs.maxWidth;
134 const props = await (0, _gatsbyCloudinary.getData)({
135 path,
136 maxWidth,
137 config: cloudinaryConfig,
138 toImgFormat: fieldArgs.toImgFormat,
139 toVideoFormat: fieldArgs.toVideoFormat,
140 toVideoPosterFormat: fieldArgs.toVideoPosterFormat
141 });
142 return props;
143 } catch (e) {
144 console.error(e);
145 return {};
146 }
147 }
148 };
149};
150
151exports.default = _default;
\No newline at end of file