Urigo / graphql-modules

Enterprise Grade Tooling For Your GraphQL Server
https://graphql-modules.com/
MIT License
1.31k stars 114 forks source link

Support third-party schema creation libraries #1466

Open kamilkisiela opened 3 years ago

kamilkisiela commented 3 years ago

Examples:

tafelnl commented 2 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)?

kamilkisiela commented 2 years ago

How do you imagine using 3p libraries for schema creation and what would be the benefit of combining it with graphql-modules?

tafelnl commented 2 years ago

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.

AlissonRS commented 2 years ago

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 GraphQLSchemas 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.

MichalLytek commented 2 years ago

Please check this super-old example of modules with TypeGraphQL: https://github.com/MichalLytek/type-graphql/tree/master/examples/graphql-modules

tafelnl commented 2 years ago

@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?

IhsenBen commented 2 years ago

So far there's no native integration of Prisma with graphql-modules?