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)
- Stitching: object field is null when all selections are delegated
- Http Executor encodes headers into query parameters which can leak Authorization headers
- Ability to get names of all the stitched queries in a middleware
- requireResolversToMatchSchema: 'warn' throws an error
- Support .astro file loading on graphql-tag-pluck HOT 1
- Troubles with connectionParams on subscriptions
- Adding content-type header is not supported when fetching schema
- Query does not provide a operation name as a property in the request body causing some server configurations to reject the request
- @graphql-tools/mock 9.0.1 causes panic: Internal errors HOT 2
- @graphql-tools/merge directive arguments compare should not require identical ordering HOT 1
- load babel options in `graphql-tag-pluck`
- [mock] relayStylePaginationMock sometimes returns an incorrect value for hasNextPage
- Batch execution throws an error when Array.prototype has additional property
- Federation @join__field requires parameter handling improvement
- filterSchema argumentFilter provides incorrect typeName
- globalGqlIdentifierName is inconsistently forced lowercase so doesn't work with mixed case identifiers HOT 1
- makeExecutableSchema fails if typeDefs includes a directive named toString
- Vite plugin a la jest-transform for GraphQL?
- Nested fields of @computed parent are not resolved HOT 1
- Handle thrown values correctly even if they are not instances of `Error`.
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.