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.
graphql-import
Advanced tools
[![Discord Chat](https://img.shields.io/discord/625400653321076807)](https://discord.gg/xud7bH9)
The graphql-import npm package allows you to import and merge GraphQL schema files. This is particularly useful for modularizing your GraphQL schema by splitting it into multiple files and then combining them into a single schema.
Importing GraphQL Schema Files
This feature allows you to import a GraphQL schema from a .graphql file. The `importSchema` function reads the file and returns the schema as a string, which can then be used with GraphQL tools like Apollo Server.
import { importSchema } from 'graphql-import';
const typeDefs = importSchema('path/to/schema.graphql');
Merging Multiple Schema Files
You can use the `importSchema` function to merge multiple GraphQL schema files into a single schema. This is useful for organizing your schema into smaller, more manageable pieces.
import { importSchema } from 'graphql-import';
const typeDefs = importSchema('path/to/rootSchema.graphql');
Using #import Syntax
The `graphql-import` package supports a special `#import` syntax that allows you to import types from other GraphQL files directly within your schema definition. This makes it easy to modularize your schema.
# import User from 'user.graphql'
# import Post from 'post.graphql'
type Query {
users: [User]
posts: [Post]
}
The `merge-graphql-schemas` package provides similar functionality by allowing you to merge multiple GraphQL schema files into one. It also supports schema stitching and type merging, making it a robust alternative to `graphql-import`.
The `graphql-tools` package from Apollo provides a set of utilities for building and manipulating GraphQL schemas. It includes functions for schema stitching, merging, and transforming schemas, offering a more comprehensive toolkit compared to `graphql-import`.
The `graphql-modules` package allows you to create modular and reusable GraphQL schemas. It provides a higher-level abstraction for organizing your schema and resolvers, making it a more feature-rich alternative to `graphql-import`.
yarn add graphql-import
import { importSchema } from 'graphql-import'
import { makeExecutableSchema } from 'graphql-tools'
const typeDefs = importSchema('schema.graphql'); // or .gql or glob pattern like **/*.graphql
const resolvers = {};
const schema = makeExecutableSchema({ typeDefs, resolvers });
Assume the following directory structure:
.
├── schema.graphql
├── posts.graphql
└── comments.graphql
schema.graphql
# import Post from "posts.graphql"
type Query {
posts: [Post]
}
posts.graphql
# import Comment from 'comments.graphql'
type Post {
comments: [Comment]
id: ID!
text: String!
tags: [String]
}
comments.graphql
type Comment {
id: ID!
text: String!
}
Running importSchema('schema.graphql')
produces the following output:
type Query {
posts: [Post]
}
type Post {
comments: [Comment]
id: ID!
text: String!
tags: [String]
}
type Comment {
id: ID!
text: String!
}
FAQs
[![Discord Chat](https://img.shields.io/discord/625400653321076807)](https://discord.gg/xud7bH9)
We found that graphql-import demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 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.