Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@graphql-tools/code-file-loader
Advanced tools
A set of utils for faster development of GraphQL tools
The @graphql-tools/code-file-loader package is part of the GraphQL Tools ecosystem and is designed to load and parse GraphQL schema definitions and documents from various file types. It supports loading from .graphql, .graphqls, .gql, .js, and .ts files. This loader is particularly useful in building GraphQL schemas directly from files, making it easier to manage and modularize GraphQL codebases.
Load GraphQL schema from code files
This feature allows developers to load GraphQL schemas directly from .graphql, .js, or .ts files. The code sample demonstrates how to use the codeFileLoader with the loadSchema function from @graphql-tools/load to asynchronously load a schema from a .graphql file.
import { loadSchema } from '@graphql-tools/load';
import { codeFileLoader } from '@graphql-tools/code-file-loader';
async function getSchema() {
const schema = await loadSchema('./schema.graphql', {
loaders: [codeFileLoader]
});
return schema;
}
Merge resolvers and type definitions
This feature supports loading and merging both resolvers and type definitions from multiple files. The code sample shows how to use loadFiles to load all resolver and type definition files from a project, and then use makeExecutableSchema to combine them into a single executable schema.
import { loadFiles } from '@graphql-tools/load-files';
import { makeExecutableSchema } from '@graphql-tools/schema';
async function buildSchema() {
const typesArray = await loadFiles('**/*.typeDefs.{js,ts}');
const resolversArray = await loadFiles('**/*.resolvers.{js,ts}');
const schema = makeExecutableSchema({
typeDefs: typesArray,
resolvers: resolversArray
});
return schema;
}
The graphql-import package allows importing and merging GraphQL SDL files. It is similar to @graphql-tools/code-file-loader but focuses more on SDL files and lacks direct support for loading from JavaScript or TypeScript files.
graphql-tag is primarily used to parse GraphQL query strings into a standard GraphQL AST. It is less about loading schemas from files and more focused on enabling the embedding and handling of GraphQL queries in JavaScript files.
FAQs
A set of utils for faster development of GraphQL tools
The npm package @graphql-tools/code-file-loader receives a total of 1,015,507 weekly downloads. As such, @graphql-tools/code-file-loader popularity was classified as popular.
We found that @graphql-tools/code-file-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.