Open kamilkisiela opened 3 years ago
Sorry for bumping this issue. But I am wondering if there is a roadmap available for this (or for this library in general)?
How do you imagine using 3p libraries for schema creation and what would be the benefit of combining it with graphql-modules?
In the legacy docs I found an implementation guide for nexus: https://www.graphql-modules.com/docs/legacy/recipes/nexus/ Something like that implementation would be great in the v2+ API as well.
This would be beneficial for several reasons. First of all it would add support for generating the schema based on code (code-first instead of schema-first). Secondly, it would allow for modules to use different schema builders.
That's how I approached using graphql-modules V1
and typegraphql
in the same project.
I created GraphQL Modules like below:
import { createModule, createApplication } from "graphql-modules";
const recipeModule = createModule({
id: "recipe",
dirname: __dirname,
typeDefs: schema,
resolvers: resolvers
});
const app = createApplication({
modules: [recipeModule]
});
const appSchema: GraphQLSchema = app.createSchemaForApollo();
Notice how createSchemaForApollo()
returns a GraphQLSchema
.
Now, typegraphql can generate the exact same GraphQLSchema
like this:
import { buildSchemaSync } from "type-graphql"; // you could use the async version too :)
import { ChatsProvider } from './chats.provider';
import { Resolver, Query } from 'type-graphql';
import { Chat } from './chat.type';
@Resolver((of) => Chat)
export class ChatResolver {
constructor(private chatsProvider: ChatsProvider) {}
@Query((returns) => [Chat])
chats() {
return this.chatsProvider.getChats();
}
}
const chatSchema: GraphQLSchema = buildSchemaSync({
resolvers: [ChatResolver],
});
Finally, you can use all the resulting GraphQLSchema
s as you please, I guess that should be enough for most cases of using both libraries in the same project, I couldn't think of a use case of creating "modules" for schemas generated by typegraphql.
Please check this super-old example of modules with TypeGraphQL: https://github.com/MichalLytek/type-graphql/tree/master/examples/graphql-modules
@AlissonRS I am not sure if I understand your point of view correctly. But it looks like you are only using graphql-modules
for "schema stitching" then? But I see great benefit in using its dependency injection too, for example.
@MichalLytek This uses the legacy version of graphql-modules
right?
So far there's no native integration of Prisma with graphql-modules?
Examples: