Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
graphql-component
Advanced tools
Reference implementation around the concept of a partial schema / component similar to that discussed [here](https://medium.com/homeaway-tech-blog/distributed-graphql-schema-development-npm-modules-d734a3cb6f12).
Reference implementation around the concept of a partial schema / component similar to that discussed here.
This example takes advantage of existing graphql stitching capabilities from Apollo, but creates a convention for how these schemas can be composed through imports and bindings.
This is very similar to the excellent graphql-modules
project — but closer to our own internal paradigm already in use for over a year and a half.
For now it is alpha, but may become an official project.
lib
- the graphql-component code.examples/example-listing/property-component
- a component implementation for Property
.examples/example-listing/reviews-component
- a component implementation for Reviews
.examples/example-listing/listing-component
- a component implementation composing Property
and Reviews
.examples/example-listing/server
- the "application".Can be run with node examples/server/index.js
or npm start
which will start with debug flags.
Enable debug logging with DEBUG=graphql-component:*
To intercept resolvers with mock fixtures execute this app with GRAPHQL_DEBUG=1
enabled.
In this example it must be done since no actual resolvers is implemented (with the exception of listing).
This works much like Apollo's addMockFunctionsToSchema
but functions better for this use case
because it will continue to use resolver when a fixture isn't present and the fixtures preserve the
memoization.
new GraphQLComponent({
// A string or array of strings representing typeDefs and rootTypes
types,
// An object containing resolver functions
resolvers,
// An optional object containing resolver dev/test fixtures
mocks,
// An optional array of imported components for the schema to be merged with
imports,
// An optional object containing custom schema directives
directives,
// An optional object { namespace, factory } for contributing to context
context,
// Enable mocks
useMocks,
// Preserve type resolvers in mock mode
preserveMockResolvers
});
This will create an instance object of a component containing the following functions:
schema
- getter that returns an executable schema.context
- context builder.Example to merge multiple components:
const { schema, context } = new GraphQLComponent({
imports: [
new Author(),
new Book(),
new BookExtension()
]
});
const server = new ApolloServer({
schema,
context
});
You can exclude root fields from imported components:
const { schema, context } = new GraphQLComponent({
imports: [
new Author(),
{
component: new Book(),
exclude: ['Query.*']
},
new BookExtension()
]
});
This will keep from leaking unintended surface area.
By simply importing an Author
component instance, it becomes possible to execute the resolver author
as a graphql call to resolve that type.
Schemas in graphql components will support the @memoize
directive. This will allow resolvers to be memoized within the
scope of a particular request context to reduce the number of times a resolver must run for the same data.
Example:
type Query {
# Seach for an author by id.
author(id: ID!, version: String) : Author @memoize
}
Example context argument:
const context = {
namespace: 'myNamespace',
factory: function (request) {
return 'my value';
}
};
FAQs
Build, customize and compose GraphQL schemas in a componentized fashion
The npm package graphql-component receives a total of 66 weekly downloads. As such, graphql-component popularity was classified as not popular.
We found that graphql-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.