I’ve followed this approach to modularize my schema:
I’ve now got a schema.js
file that looks like this:
import { makeExecutableSchema } from 'graphql-tools';
import resolvers from './resolvers';
import * as donations from '../donations.js';
import * as projects from '../projects.js';
import * as partners from '../partners.js';
import * as donors from '../donors.js';
const schema = `
scalar GraphQLDate
# Queries that the schema supports
type Query {
donations(projectId: Int, donorId: Int): [Donation]
donors: [Donor]
projects(partnerId: Int): [Project]
partners: [Partner]
}
`;
export default makeExecutableSchema({
typeDefs: [
schema,
donations.schema,
projects.schema,
partners.schema,
donors.schema
],
resolvers,
})
It works successfully but I’m unhappy about having to define my queries in the main schema.js
file and would prefer to define them along with each object in that file - e.g. partners, projects etc.