Open artecoop opened 2 years ago
What does fooResolver
and barResolver
look like?
I'm not sure but my understanding from your example is that it looks like this
import { IResolvers } from 'mercurius';
const resolvers: IResolvers = {
Query: {
list: async () => await getAll()
},
Mutation: {
manage: async (_root, { input }) => await manage(input),
delete: async (_root, { id }) => await deleteString(id)
}
};
export default resolvers;
Then you're merging them like this
import fooResolver from './modules/foo/resolvers';
import barResolver from './modules/bar/resolvers';
export const resolvers = { ...fooResolvers, ...barResolvers };
which causes Query
and Mutation
objects to keep getting overridden
You probably want to compose it in a different way like
import { fooQueries, fooMutations } from 'modules/foo'
import { barQueries, barMutation } from 'modules/bar'
const resolvers = {
Query: {...fooQueries, ...barQueries},
Mutations: {...fooMutations, ...barMutations}
}
I understand your confusion, because of the naming clash, but when I'm importing, resolvers refers to the file name as stated on the structure of the project. I'm not referencing the const resolvers: IResolvers ...
(which isn't exported btw).
Hello Everyone, I have a pretty large project that I'm trying to move to graphql using fastify, mercurius, mercurius-codegen and mercurius-integration-testing
I've split my business logic into modules, so the code is structured like this
base.ts
contains the root query and mutation, in order to let other schema.ts files to extendA schema file contains something like this
Here's a resolver:
In order to avoid bloating the server.ts file, I've created an application.ts to import all the schemas and resolvers
The problem arises when I need to set up mercurius:
With resolvers merged with the spread operator, all are overwritten by the last one.
Using
mergeResolvers
from graphql-tools create a different problemgive me this error
Any help?