-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
Hi @leveluptuts, I found a good way to modularize the API codes. I suggest you use bundle from graphql-modules. Take a look at my code https://bitbucket.org/raphox/react-fullstack/src/master/imports/api/
The main code:
// resolutions.js
...
const schema = `
type Resolution {
_id: String
name: String
author: Author
}
`;
export const queries = `
resolutions: [Resolution]
resolution(_id: String): Resolution
`;
export const mutations = `
createResolution(name: String!): Resolution
removeResolution(_id: String!): Resolution
`;
const resolvers = {
queries: {
resolutions() {
...
},
mutations: {
createResolution(obj, { name }, context) {
...
},
Resolution: {
author(resolution) {
return Authors.findOne(resolution.author);
}
}
}
export default () => ({
schema,
queries,
mutations,
resolvers,
modules: [authors]
});// register-api.js
import resolutions from '../../api/resolutions';
const modules = [resolutions];
const schema = makeExecutableSchema(bundle(modules));
createApolloServer({
schema
});I still need to finalize the implementation, but I can already work with multiple queries, schemas and mutations.
References:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels