![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
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 is very similar to the excellent graphql-modules
project — but a little closer to our own internal paradigm already in use for over a year and a half and adds some features such as exclude
root types from imports
and memoize resolvers.
In fact, this module utilizes the graphql-toolkit
developed by the graphql-modules
team to merge types and resolvers.
Experimental / alpha for now.
lib
- the graphql-component code.test/examples/example-listing/property-component
- a component implementation for Property
.test/examples/example-listing/reviews-component
- a component implementation for Reviews
.test/examples/example-listing/listing-component
- a component implementation composing Property
and Reviews
.test/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 mocks execute this app with GRAPHQL_DEBUG=1
enabled.
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.Typically the best way to make a re-useable component will be to extend GraphQLComponent
.
const GraphQLComponent = require('graphql-component');
const Resolvers = require('./resolvers');
const Types = require('./types');
const Mocks = require('./mocks');
class PropertyComponent extends GraphQLComponent {
constructor({ useMocks, preserveTypeResolvers }) {
super({ types: Types, resolvers: Resolvers, mocks: Mocks, useMocks, preserveTypeResolvers });
}
}
module.exports = PropertyComponent;
This will allow for configuration (in this example, useMocks
and preserveTypeResolvers
) as well as instance data per component (such as data base clients, etc).
Example to merge multiple components:
const { schema, context } = new GraphQLComponent({
imports: [
new Property(),
new Reviews()
]
});
const server = new ApolloServer({
schema,
context
});
You can exclude root fields from imported components:
const { schema, context } = new GraphQLComponent({
imports: [
{
component: new Property(),
exclude: ['Mutation.*']
},
{
component: new Reviews(),
exclude: ['Mutation.*']
}
]
});
This will keep from leaking unintended surface area.
Example context argument:
const context = {
namespace: 'myNamespace',
factory: function ({ req }) {
return 'my value';
}
};
After this, resolver context
will contain { ..., myNamespace: 'my value' }
.
It may be necessary to transform the context before invoking component context.
const { schema, context } = new GraphQLComponent({types, resolvers, context});
context.use('transformRawRequest', ({ request }) => {
return { req: request.raw.req };
});
Using context
now in apollo-server-hapi
for example, will transform the context to one similar to default apollo-server
.
graphql-component accepts mocks in much the same way that Apollo does but with one difference.
Instead of accepting a mocks object, it accepts (importedMocks) => mocksObject
argument. This allows components to utilize the mocks from other imported components easily.
FAQs
Build, customize and compose GraphQL schemas in a componentized fashion
The npm package graphql-component receives a total of 17 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 0 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.