Coder Social home page Coder Social logo

Comments (6)

danielrearden avatar danielrearden commented on May 18, 2024 1

I'm not that familiar with NestJS, but I believe if you provide both typePaths and typeDefs, the resulting type definitions should be merged together. So you should be able to do:

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { schemaDirectives, typeDefs } from 'sqlmancer';

import { UserModule } from './user/user.module';

@Module({
    imports: [
        UserModule,
        GraphQLModule.forRoot({
            typePaths: [`${__dirname}/**/*.graphql`],
            schemaDirectives,
            typeDefs,
        }),
    ],
})
export class AppModule {}

from sqlmancer.

danielrearden avatar danielrearden commented on May 18, 2024

Hi @unlight Thanks for the bug report.

The directives included in schemaDirectives will not include all possible directives -- only the ones that actually transform the schema as opposed to just conveying some information about your database. So what you're seeing in the console is accurate.

The errors you're seeing indicates a possible issue with the SDL type definitions for the directives. If you're not using makeSqlmancerSchema, then the type definitions have to be added manually as shown here

import { typeDefs, schemaDirectives } from 'sqlmancer';
import { ApolloServer } from 'apollo-server';

const apollo = new ApolloServer({
  typeDefs: [yourTypeDefs, typeDefs],
  resolvers: yourResolvers,
  schemaDirectives: { ...yourSchemaDirectives, ...schemaDirectives },
});

Can you share a more complete example of how you're creating your schema, including any imports?

from sqlmancer.

unlight avatar unlight commented on May 18, 2024

I'm using NestJS with schema first approach (I tried code first, but seems it's not yet supported).

Main file looks like

import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { schemaDirectives } from 'sqlmancer';

import { UserModule } from './user/user.module';

@Module({
    imports: [
        UserModule,
        GraphQLModule.forRoot({
            typePaths: [`${__dirname}/**/*.graphql`],
            schemaDirectives: {
                ...schemaDirectives,
            },
        }),
    ],
})
export class AppModule {}

So, there is no typeDefs or resolvers mentions in NestJS tutorials, however GraphQLModule.forRoot can accept them according to signature.
typeDefs, resolvers is generated somewhere under the hood of NestJs from decorated classes/methods.

from sqlmancer.

unlight avatar unlight commented on May 18, 2024

Thank you, that's worked.
But NestJS's GraphQLModule typeDefs expects string

typeDefs: typeDefs.loc!.source.body,

from sqlmancer.

danielrearden avatar danielrearden commented on May 18, 2024

@unlight As a temporary workaround, you can do

import { print } from 'graphql'
...
typeDefs: print(typeDefs), 

I can export the typeDefs as a string in the next release.

from sqlmancer.

danielrearden avatar danielrearden commented on May 18, 2024

It would also be worthwhile to document NestJS integration alongside any other commonly-used libraries

from sqlmancer.

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.