gatsby-source-sanity
Version:
Gatsby source plugin for building websites using Sanity.io as a backend.
90 lines • 3.29 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const graphql_1 = require("gatsby/graphql");
const cache_1 = require("../util/cache");
const getGatsbyImageProps_1 = require("./getGatsbyImageProps");
const ImageFormatType = new graphql_1.GraphQLEnumType({
name: 'SanityImageFormat',
values: {
NO_CHANGE: { value: '' },
JPG: { value: 'jpg' },
PNG: { value: 'png' },
WEBP: { value: 'webp' },
},
});
const extensions = new Map();
function extendImageNode(context, config) {
const key = cache_1.getCacheKey(config, cache_1.CACHE_KEYS.IMAGE_EXTENSIONS);
if (extensions.has(key)) {
return extensions.get(key);
}
const extension = getExtension(config);
extensions.set(key, extension);
return extension;
}
exports.extendImageNode = extendImageNode;
function getExtension(config) {
const location = { projectId: config.projectId, dataset: config.dataset };
const 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: (image, args) => getGatsbyImageProps_1.getFixedGatsbyImage(image, args, location),
};
const 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: (image, args) => getGatsbyImageProps_1.getFluidGatsbyImage(image, args, location),
};
return { fixed, fluid };
}
//# sourceMappingURL=extendImageNode.js.map