Hi @thedavid i can provide a little bit more information about core concepts of graphql-compose.
graphql-compose – is a core plugin that provides a lot of sugar for schema creation. It supports SDL first & code-first approaches for graphql schema construction. For example, you may use SDL for some type creation and then switch to code approach SchemaComposer · graphql-compose
Graphql-compose allows to call addTypeDefs()
and addResolveMethods()
as many times as you need, before you call buildSchema()
.
- import { makeExecutableSchema } from 'graphql-tools';
+ import { schemaComposer } from 'graphql-compose';
- export const schema = makeExecutableSchema({
- typeDefs,
- resolvers,
- });
+ schemaComposer.addTypeDefs(typeDefs);
+ schemaComposer.addResolveMethods(resolvers);
+ export const schema = schemaComposer.buildSchema();
When you call addTypeDefs
it will create TypeComposer objects which allow modifying types (add, remove fields & args). So when you made all modification & schema generation steps you need to call schemaComposer.buildSchema()
for creation GraphQLSchema
instance which will work with apollo-server or graphql-express.
So graphql-compose was created for schema generation. For example you have some models (e.g. mongoose) and then you may traverse their schemas and call graphql-compose methods for creating graphql types. I started using this approach 3 years ago and from that time was created graphql-compose-mongoose package which uses mongoose models as source and as output provides for you graphql types with different resolvers (find, create, update and other resolvers). Also when graphql-compose-mongoose generates for you types from models and you may remove any sensitive fields (eg password) and add new fields and relation with any other data sources.
On top of graphql-compose I’ve created a lot of different plugins:
- graphql-compose-mongoose – generates types & resolvers from mongoose models
- graphql-compose-elasticsearch – generates types & search resolver from elastic mapping
- graphql-compose-json – generates types from JSON objects
- graphql-compose-aws – generates graphql api from AWS cli schema files
- graphql-compose-bullmq – generates API for bullmq
- and of course, you may create any your own type generator on top of graphql-compose
And the last most interesting tool which we use internally for almost 1 year is GitHub - graphql-compose/graphql-compose-modules Sorry but it still does not have documentation. But you may see tests or example. This tool creates schema from folder structure – it scans some folder and creates schema for them. It was inspired by NextJS, how it uses page/ folder for routing creation.
Redwood handles resolvers for you when creating it’s GraphQL API function. Wondering out loud how/if this is compatible. Do you have any initial guesses?
David, can you provide a link to your resolvers and I can see how graphql-compose can be used in your case.