gatsby-source-sanity
Version:
Gatsby source plugin for building websites using Sanity.io as a backend.
90 lines • 3.32 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var graphql_1 = require("gatsby/graphql");
var cache_1 = require("../util/cache");
var getGatsbyImageProps_1 = require("./getGatsbyImageProps");
var ImageFormatType = new graphql_1.GraphQLEnumType({
name: 'SanityImageFormat',
values: {
NO_CHANGE: { value: '' },
JPG: { value: 'jpg' },
PNG: { value: 'png' },
WEBP: { value: 'webp' },
},
});
var extensions = new Map();
function extendImageNode(context, config) {
var key = cache_1.getCacheKey(config, cache_1.CACHE_KEYS.IMAGE_EXTENSIONS);
if (extensions.has(key)) {
return extensions.get(key);
}
var extension = getExtension(config);
extensions.set(key, extension);
return extension;
}
exports.extendImageNode = extendImageNode;
function getExtension(config) {
var location = { projectId: config.projectId, dataset: config.dataset };
var fixed = {
type: new graphql_1.GraphQLObjectType({
name: 'SanityImageFixed',
fields: {
base64: { type: graphql_1.GraphQLString },
aspectRatio: { type: graphql_1.GraphQLFloat },
width: { type: graphql_1.GraphQLFloat },
height: { type: graphql_1.GraphQLFloat },
src: { type: graphql_1.GraphQLString },
srcSet: { type: graphql_1.GraphQLString },
srcWebp: { type: graphql_1.GraphQLString },
srcSetWebp: { type: graphql_1.GraphQLString },
},
}),
args: {
width: {
type: graphql_1.GraphQLInt,
defaultValue: getGatsbyImageProps_1.DEFAULT_FIXED_WIDTH,
},
height: {
type: graphql_1.GraphQLInt,
},
toFormat: {
type: ImageFormatType,
defaultValue: '',
},
},
resolve: function (image, args) { return getGatsbyImageProps_1.getFixedGatsbyImage(image, args, location); },
};
var fluid = {
type: new graphql_1.GraphQLObjectType({
name: 'SanityImageFluid',
fields: {
base64: { type: graphql_1.GraphQLString },
aspectRatio: { type: graphql_1.GraphQLFloat },
src: { type: graphql_1.GraphQLString },
srcSet: { type: graphql_1.GraphQLString },
srcWebp: { type: graphql_1.GraphQLString },
srcSetWebp: { type: graphql_1.GraphQLString },
sizes: { type: graphql_1.GraphQLString },
},
}),
args: {
maxWidth: {
type: graphql_1.GraphQLInt,
defaultValue: getGatsbyImageProps_1.DEFAULT_FLUID_MAX_WIDTH,
},
maxHeight: {
type: graphql_1.GraphQLInt,
},
sizes: {
type: graphql_1.GraphQLString,
},
toFormat: {
type: ImageFormatType,
defaultValue: '',
},
},
resolve: function (image, args) { return getGatsbyImageProps_1.getFluidGatsbyImage(image, args, location); },
};
return { fixed: fixed, fluid: fluid };
}
//# sourceMappingURL=extendImageNode.js.map