Coder Social home page Coder Social logo

Support of multiple endpoints about graphql HOT 10 CLOSED

nestjs avatar nestjs commented on April 23, 2024
Support of multiple endpoints

from graphql.

Comments (10)

kamilmysliwiec avatar kamilmysliwiec commented on April 23, 2024 1

Since 5.1.0 you can restrict modules that should be included in the lookup process. For instance, if you want only resolvers from CatsModule and DogsModule to be included, simply pass them into include array:

GraphQLModule.forRoot({
    typePaths: ['./**/*.graphql'],
    include: [CatsModule, DogsModule],
}),

from graphql.

kamilmysliwiec avatar kamilmysliwiec commented on April 23, 2024 1

Thanks for repo @Rockson. Just fixed the issue, update your graphql package into 5.3.1!

from graphql.

krivochenko avatar krivochenko commented on April 23, 2024

There is one more problem. Before I have used GraphQLFactory.createSchema, for create schema with custom settings.

const typeDefs = this.graphQLFactory.mergeTypesByPaths('src/admin/**/*.graphql');
const resolverValidationOptions: IResolverValidationOptions = {allowResolversNotInSchema: true};
const schema = this.graphQLFactory.createSchema({typeDefs, resolverValidationOptions});

But for now this method dropped.

from graphql.

krivochenko avatar krivochenko commented on April 23, 2024

So, I have two modules: SiteModule and AdminModule. Each of them imports GraphQLModule. AdminModule also imports AuthModule with some, for example, AuthResolver in providers. SiteModule sees AuthResolver too, but in *.graphql files inside SiteModule there isn't mutation which exists in AuthResolver.

For now if in root-module I import so:

imports: [
  SiteModule,
  AdminModule,
],

I get error: Error: "Mutation" defined in resolvers, but not in schema. If I change order:

imports: [
  AdminModule,
  SiteModule,
],

I don't get errors during start of application, but I get 404, when I try to get /site.
I think we need a way to pass resolverValidationOptions here or reimplement ResolversExplorerService.

from graphql.

krivochenko avatar krivochenko commented on April 23, 2024

@kamilmysliwiec thanks for your work! I think, in some cases include property can be useful, but not in my. Let's imagine, we have CatsModule with CatsResolver. In CatsResolver there is queries for getting one or many cats. Also in the same resolver there is a mutation for editing of cat. Queries enabled for all users, but mutation only for administrators. So we don't need include information about mutation in schema of public API, but we have to include CatsModule for both endpoint.

from graphql.

Rockson avatar Rockson commented on April 23, 2024

@kamilmysliwiec I Can't make it work with forRootAsync

This works

GraphQLModule.forRoot({
    typePaths: ['./admin/**/*.graphql'],
    include: [AdminModule],
    path: '/admin'
}),
GraphQLModule.forRoot({
    typePaths: ['./client/**/*.graphql'],
    include: [ClientModule],
    path: '/client'
}),

this doesn't, only the admin endpoint is available

    GraphQLModule.forRootAsync({
      imports: [ConfigModule],
      useExisting: AdminGqlConfigService,
    }),
    GraphQLModule.forRootAsync({
      imports: [ConfigModule],
      useExisting: ClientGqlConfigService,
    }),

GqlConfigs: https://gitlab.com/fabio.rizzello.lav/nest-graphql-multiple-endpoints-forRootasync-issue/blob/master/src/app/GqlConfigService.ts

ConfigModule: https://gitlab.com/fabio.rizzello.lav/nest-graphql-multiple-endpoints-forRootasync-issue/blob/master/src/app/config.module.ts

Here is the demo repo:
https://gitlab.com/fabio.rizzello.lav/nest-graphql-multiple-endpoints-forRootasync-issue
Start the server: /gqladmin is available but /gqlclient returns 404

I'm using nest 5.3.0

from graphql.

kamilmysliwiec avatar kamilmysliwiec commented on April 23, 2024

Have you tried updating all packages to recent patch versions?

from graphql.

Rockson avatar Rockson commented on April 23, 2024

My package json

    "@nestjs/common": "^5.3.7",
    "@nestjs/core": "^5.3.7",
    "@nestjs/graphql": "^5.3.0",

I removed node_modules and then installed dependencies again

The problem persists

from graphql.

Rockson avatar Rockson commented on April 23, 2024

@kamilmysliwiec
Has I've written in gitter, I think there is a problem when including the endpoint's modules

Here is the repo updated https://gitlab.com/fabio.rizzello.lav/nest-graphql-multiple-endpoints-forRootasync-issue

Is similar to the previous one I've only implemented the resovler viewer inside the clientResolver
https://gitlab.com/fabio.rizzello.lav/nest-graphql-multiple-endpoints-forRootasync-issue/blob/master/src/gql/client/client.resolver.ts
Looks like nest doesn't register the resolver because the function isn't called

from graphql.

lock avatar lock commented on April 23, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.