Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
gatsby-plugin-source-graphql-files
Advanced tools
Sources graphql files statically to use with gatsby-image e.g. and allows transform graphql fields containing links to the remote files to point to the static file nodes.
Let's say you are using a headless cms like strapi as content source and for your final gatsby site you want all media that points to that cms to be included statically. This is what this plugin is intended for. Furthermore it allows you to use images with gatsby-image.
This plugin is a work in progress and could potentially contain a lot of bugs. Contributions are very welcome.
You can specify the transformFields
option to add additional fields where the remote links are replaced with the static url's.
// In your gatsby-config.js
module.exports = {
plugins: [
resolve: `gatsby-plugin-source-graphql-files`,
options: {
sources: {
endpoint: 'https://example.com/graphql',
query: `
{
files {
id
url
}
}
`,
source: ({ files }) => files,
},
files: {
typeName: 'CMS_UploadFile',
},
transformFields: [
{
baseUrl: 'https://example.com',
typeName: 'CMS_ComponentContentParagraph',
fieldName: 'Content',
},
],
},
]
}
Note: In order to resolve the correct file node you must include the id in your queries like so:
{
cms {
files {
id # <- Don't forget
staticFile {
publicURL
}
}
}
}
sources
: SourceOptions | Array<SourceOptions>interface SourceOptions {
endpoint: string // Graphql endpoint
query: string // Query to fetch url's and id's
// A function to map the query result to an array of url's and id's
source: (queryResult: Object) => Array<{ url: string; id: string }>
options?: Object // @see graphql-request
variables?: Object
}
files
: FileOptions | Array<FileOptions>interface FileOptions {
typeName: string // Graphql type that will get the static field added
staticFieldName?: string // @default 'staticFile'
}
transformFields
: TransformFieldOptions | Array<TransformFieldOptions>interface TransformFieldOptions {
baseUrl: string // Url that will be used in the regex to find remote file url's
typeName: string // Graphql type to add transformation field
fieldName: string // The field that contains the content to transform
transformFieldName?: string // @default <fieldName>Transformed
/*
* Functiont that produces a regular expression to match remote url's
* @default ({ baseUrl }) => new RegExp(`${_.escapeRegExp(baseUrl)}[^ )]+`, 'g')
*/
regex?: (options: TransformFieldOptions) => RegExp
}
This plugin sources files by querying graphql endpoints for files and then utilizing gatsby-source-filesystem
to download them. Afterwards the graphql types specified under the files
option get an additional field that points to the downloaded file node.
For the transformation of fields a regular expression is used to identify remote file paths and replace them with their static counterpart.
FAQs
Sources graphql files statically to use with gatsby-image e.g. and allows transform graphql fields containing links to the remote files to point to the static file nodes.
The npm package gatsby-plugin-source-graphql-files receives a total of 4 weekly downloads. As such, gatsby-plugin-source-graphql-files popularity was classified as not popular.
We found that gatsby-plugin-source-graphql-files demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.