Comments (6)
Here is a small project I've being working on https://github.com/lucasconstantino/graphql-modules/
from graphql-tools.
Hi, I created a package that allows for modular definition of graphql schemas. It can be found here. Would be great if something like this would be in the core ;)
https://www.npmjs.com/package/apollo-modules
from graphql-tools.
@tomitrescak your package looks interesting, but I'm a bit confused because it seems to do more than just let you create a schema in a modular way. For example, there's also a function to create input types from output types, and a function to modify options based on the request.
I think it would be best if modular schema creation was limited to just the schema itself, and allowed you to start with a base schema and then extend that with modules. Unfortunately that would require modifications to graphql-js or monkey patching a schema. If I were to implement it, I think I would just try monkey patching an existing schema, but that could be rather tedious programming work and is probably pretty error-prone.
from graphql-tools.
I'm also very interested in this, relating back to apollographql/apollo#28. It's currently a lot of work for devs to add "apollo packages" (packages that include their own schema). I know it's possible to gradually construct the typeDefs via imported arrays, but there's no way to add root queries and mutations.
I was going to propose the following API:
const es = makeExecutableSchema(...);
es.addType(name, definition);
es.addRootQuery(name, definition);
es.addRootMutation(name, definition);
es.remove*(name, definition);
This is break from the common way of setting up everything in advance, and instead does a lot at "runtime", making it more efficient for HMR and potentially allowing for "runtime packages" (that are installed in a running app).
But if I understood correctly, the proposal here is much better. However, @tomitrescak, I couldn't quite understand from the README what it would look like. Any chance of an example somewhere of how both an app, and package, would use this with each other?
from graphql-tools.
@gadicc I have recently updated the documentation.
My "solution" thinks a lot about importing modules from the packages.
All you need to do is import all modules from the package when you are constructing your schema:
import { addModules } from 'apollo-modules';
import { makeExecutableSchema } from 'graphql-tools';
import { modules } from 'my-package';
const modules = addModules(modules);
// build your schema
const schema = makeExecutableSchema({ typeDefs: modules.schema, resolvers: modules.resolvers);
Using the below definition of modules, you can even specify how given module changes context on each request in modifyOptions
function:
interface ApolloModule {
// definition of types
schema: string;
// definition of queries
queryText?: string;
// implementation of queries
queries?: Object;
// implementation of type resolvers
resolvers?: Object;
// definition of mutations
mutationText?: string;
// implmentation of mutations
mutations?: Object;
// allows you to modify apollo Options (e.g. context) based on current request
modifyOptions?: (req: any, apolloOptions: ApolloOptions) => void
}
The REAL downside of this approach is that this would have to become a "standard" as you need to construct your whole schema using apollo-modules
and you cannot combine approaches.
from graphql-tools.
This is a great solution, for now we have these directions as well: http://dev.apollodata.com/tools/graphql-tools/generate-schema.html#modularizing
I think adding the following specific feature will resolve the rest of the needs for which one would currently need apollo-modules
: #182
But I'm excited about continued innovation in schema development!
from graphql-tools.
Related Issues (20)
- Issue: SyntaxError when using @graphql-tools/import with Node.js (v20 or v22)
- New feature: fetch Apollo Managed Federation supergraph from GraphOS
- Unexpected error "You must pass a scope and parentPath unless traversing a Program/File" HOT 3
- MockStore find and filter fail if no items have ever been added for the type
- Avoid using Babel in `graphql-tag-pluck`'s `gqlPluckFromCodeString` where possible
- Update @graphql-tools/executor peer dependencies to exclude graphql v16 HOT 2
- Directives on root fields are lost in subschema requests
- Add tests to Fed compat repo for mutations with computed fields on interfaces
- directive on FIELD_DEFINITION doesn't get called when subscribe
- Support Custom Directives for Mutation Input Variables
- Add resolverValidationOptions parameter to addMocksToSchema
- @graphql-tools/delegate requires TypeScript lib ESNext
- @graphql-tools/delegate - prepareGatewayDocument - selection are getting pushed to the stack HOT 3
- DeprecationWarning: Use of deprecated double slash
- Support using GraphQL 17 alpha without legacy-peer-deps HOT 2
- Allow MockStore get and set methods to successfully handle input types
- Regression in the getDirectives function HOT 1
- `makeDirectiveNodes` appears to be called twice for the same directive when printing the schema in 10.5.3. HOT 3
- Percent symbol (%) is classified as invalid path
- Improve handling of selections that would only consist of `__typename`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-tools.