Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
graphql-import
Advanced tools
Import & export definitions in GraphQL SDL (also refered to as GraphQL modules)
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`.
Import & export definitions in GraphQL SDL (also refered to as GraphQL modules)
yarn add graphql-import
import { importSchema } from 'graphql-import'
import { makeExecutableSchema } from 'graphql-tools'
const typeDefs = importSchema('schema.graphql')
const resolvers = {}
const schema = makeExecutableSchema({ typeDefs, resolvers })
Assume the following directory structure:
.
├── a.graphql
├── b.graphql
└── c.graphql
a.graphql
# import B from "b.graphql"
type A {
# test 1
first: String @first
second: Float
b: B
}
b.graphql
# import C from 'c.graphql'
type B {
c: C
hello: String!
}
c.graphql
type C {
id: ID!
}
Running console.log(importSchema('a.graphql'))
procudes the following output:
type A {
first: String @first
second: Float
b: B
}
type B {
c: C
hello: String!
}
type C {
id: ID!
}
Please refer to src/index.test.ts
for more examples.
FAQs
[![Discord Chat](https://img.shields.io/discord/625400653321076807)](https://discord.gg/xud7bH9)
The npm package graphql-import receives a total of 126,552 weekly downloads. As such, graphql-import popularity was classified as popular.
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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.