Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.