Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@rollup/plugin-graphql
Advanced tools
@rollup/plugin-graphql is a Rollup plugin that allows you to import GraphQL files into your JavaScript or TypeScript projects. This can be particularly useful for bundling GraphQL schema or query files directly into your application, making it easier to manage and deploy GraphQL-related code.
Import GraphQL Files
This feature allows you to import GraphQL files directly into your JavaScript or TypeScript code. The imported schema or query can then be used within your application.
import schema from './schema.graphql';
console.log(schema);
Bundling GraphQL Files
This feature demonstrates how to use the @rollup/plugin-graphql to bundle GraphQL files along with your JavaScript code using Rollup. The plugin processes the GraphQL files and includes them in the final bundle.
import { rollup } from 'rollup';
import graphql from '@rollup/plugin-graphql';
const inputOptions = {
input: 'src/index.js',
plugins: [graphql()]
};
const outputOptions = {
file: 'bundle.js',
format: 'cjs'
};
async function build() {
const bundle = await rollup(inputOptions);
await bundle.write(outputOptions);
}
build();
graphql-tag is a JavaScript template literal tag that parses GraphQL queries. It is commonly used with Apollo Client and other GraphQL clients. Unlike @rollup/plugin-graphql, graphql-tag does not handle file imports directly but focuses on parsing GraphQL queries from template literals.
graphql-import allows you to import .graphql files into your JavaScript or TypeScript code. It is similar to @rollup/plugin-graphql in that it helps manage GraphQL schema and query files, but it is not a Rollup plugin and does not handle bundling.
babel-plugin-import-graphql is a Babel plugin that allows you to import GraphQL files into your JavaScript code. It is similar to @rollup/plugin-graphql but is designed to work with Babel instead of Rollup.
🍣 A Rollup plugin which Converts .gql/.graphql(s) files to ES6 modules.
This plugin requires an LTS Node version (v10.0.0+) and Rollup v1.20.0+.
Using npm:
npm install @rollup/plugin-graphql --save-dev
Create a rollup.config.js
configuration file and import the plugin:
import graphql from '@rollup/plugin-graphql';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'cjs'
},
plugins: [graphql()]
};
Then call rollup
either via the CLI or the API.
With an accompanying file src/index.js
, you can import GraphQL files or named queries/mutations:
// src/index.js
// import a GraphQL Document from a GraphQL file,
import schema from './schema.graphql';
// or import named Query/Mutation
import { BatmanQuery, JokerMutation } from './schema.graphql';
Thanks to graphql-tag, fragments import is supported by using #import "..."
.
Given the following file heroFragment.graphql
:
fragment HeroFragment on Hero {
id
name
}
You can import it like this:
#import "./heroFragment.graphql"
query AllHeroes {
heros {
...HeroFragment
}
}
exclude
Type: String
| Array[...String]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
include
Type: String
| Array[...String]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
FAQs
Convert .gql/.graphql files to ES6 modules
The npm package @rollup/plugin-graphql receives a total of 155,089 weekly downloads. As such, @rollup/plugin-graphql popularity was classified as popular.
We found that @rollup/plugin-graphql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.