type-graphql
type-graphql copied to clipboard
Two mounted apollo servers (resolvers with inhertance) – second one lacks ArgsType in query
Describe the Bug
We are creating two schemas, 2 initializing 2 apollo servers (apollo-server-express
), then trying to mount them on two different paths: /graphql
and /cci
To Reproduce This example includes parts of code
@ArgsType()
export class PaginationArgs {
@Field((type) => Int, { defaultValue: 0 })
offset!: number;
@Field((type) => Int)
take!: number;
}
@ArgsType()
export class OrderArgs {
@Field({ defaultValue: "_id" })
sortBy!: string;
// @Field((type) => SortOrder, { defaultValue: SortOrder.desc })
// order!: SortOrder;
}
@Resolver((of) => itemType, { isAbstract: false })
class AbstractResolverClass {
@Query(returns => Task)
['tasks'+Math.floor(Math.random() *1000)](
@Args() { offset, take }: PaginationArgs,
@Args() { sortBy }: OrderArgs,
) {
}
@FieldResolver()
['field'+Math.floor(Math.random() *1000)](
@Args() { offset, take }: PaginationArgs,
@Args() { sortBy }: OrderArgs,
): number {
return Math.random()
}
}
// example of build function
export const buildCciApolloServer = async (httpServer: http.Server) => {
const schema = await buildSchema({
resolvers: [
TaskResolver,
// TestResolver
],
nullableByDefault: true,
scalarsMap: [{ type: Types.ObjectId, scalar: ID }],
globalMiddlewares: [TypegooseMiddleware],
authChecker: null
});
const server = new ApolloServer<ApolloContext>({
schema,
plugins: [
ApolloServerPluginDrainHttpServer({ httpServer }),
ComplexityPlugin({
schema,
maxComplexity: 100,
estimators: [simpleEstimator({ defaultComplexity: 1 })],
}),
],
context: graphqlAuthContext,
});
return server;
};
// init
const cciApolloServer = await buildCciApolloServer(httpServer)
const apiApolloServer = await buildApiApolloServer(httpServer)
await cciApolloServer.start()
await apiApolloServer.start()
cciApolloServer.applyMiddleware({ app, path: '/cci' })
apiApolloServer.applyMiddleware({ app, path: '/graphql' });
As the result, second built server don't have args that are defined via @ArgsType()
First server: args are here
Second server: no args available
Please create a minimal reproducible code example repository. So that I can run it and debug what's happening. Your code snippets are incomplete.
Hey @MichalLytek Check this out: https://github.com/Alex0007/graphql-argstype-bug
I can reproduce and confirm the issue.
It not happens when the resolver is build without inheritance (generic function). So the build function is mutating the metadata making it losses info about args. Need to debug and dig further.