Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
merge-graphql-schemas
Advanced tools
When using graphql-tools, a package from the ApolloStack Team, to combine our
types and resolvers, we call the function makeExecutableSchema()
, passing the full schema as a string, and a resolvers object.
For the schema file, we can create it as a single string containing all types. But as the app grows, so does the size/complexity of this file. On the other hand, if we put every type in its own file, we need a way of merging all that information back into one string. Apollo lets us pass multiple strings, which lets us separate types, but the root queries for those types still need to be merged with the root query and mutation objects. We would like to be able to specify a types and queries that belong to the same domain together:
ClientType
type Client {
id: ID!
name: String
age: Int
products: [Product]
}
type Query {
clients: [Client]
client(id: ID!): Client
}
ProductType
type Product {
id: ID!
description: String
price: Int
}
type Query {
products: [Product]
product(id: ID!): Product
}
Merged Result
type Client {
id: ID!
name: String
age: Int
products: [Product]
}
type Product {
id: ID!
description: String
price: Int
}
# This part is hard because everything is in unparsed GraphQL language (string):
type Query {
clients: [Client]
client(id: ID!): Client
products: [Product]
product(id: ID!): Product
}
It's the same for our resolvers: Create everything in one big/complex file/object or merge multiple files/objects into one.
This package will allow you to just specify a folder or a set of imports to merge. mergeGraphqlSchemas()
will merge not only your types but also root queries in the correct format to be passed to makeExecutableSchema()
. We could also go one step further and actually call makeExecutableSchema
.
Our function mergeGraphqlSchemas
should be able to receive:
We could define some conventions and, for example, consider that the '/graphql' folder contains a '/types' and a '/resolvers' folder. In that case, we could allow the API to be called with no arguments.
const executableSchema = mergeGraphqlSchemas();
app.use(
'/graphql',
bodyParser.json(),
apolloExpress({ schema: executableSchema })
);
Only passing a folder directory:
const executableSchema = mergeGraphqlSchemas('./graphql');
app.use(
'/graphql',
bodyParser.json(),
apolloExpress({ schema: executableSchema })
);
Passing an array of type definitions (we would be fetching resolvers from the same files):
const executableSchema = mergeGraphqlSchemas([ClientType, ProductType, ...]);
app.use(
'/graphql',
bodyParser.json(),
apolloExpress({ schema: executableSchema })
);
Passing an options object:
const executableSchema = mergeGraphqlSchemas({
typesFolder: './graphql/types', // get everything in this folder
resolversFolder: './graphql/resolvers',
types: [ClientType, ProductType], // or specify objects you import yourself
resolvers: [ClientResolvers, ProductResolvers]
rootQueryName: 'Query',
rootMutationName: 'Mutation',
...
})
app.use(
'/graphql',
bodyParser.json(),
apolloExpress({ schema: executableSchema })
);
FAQs
A utility library to facilitate merging of modularized GraphQL schemas and resolver objects.
The npm package merge-graphql-schemas receives a total of 7,076 weekly downloads. As such, merge-graphql-schemas popularity was classified as popular.
We found that merge-graphql-schemas demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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.