Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing directives (NestJS integration) #113

Open
unlight opened this issue Jun 14, 2020 · 6 comments
Open

Missing directives (NestJS integration) #113

unlight opened this issue Jun 14, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@unlight
Copy link

unlight commented Jun 14, 2020

Following 'Getting Started' documentation, I'm getting error

(node:868) UnhandledPromiseRejectionWarning: Error: Unknown argument "dialect" on directive "@sqlmancer".

Unknown argument "table" on directive "@model".

Unknown argument "pk" on directive "@model".
import { schemaDirectives} from 'sqlmancer';
console.log('schemaDirectives', schemaDirectives);

image

Looks like it's not all from https://sqlmancer.netlify.app/directives
At least model, sqlmancer are missing.

sqlmancer@0.3.3

@danielrearden danielrearden added the bug Something isn't working label Jun 14, 2020
@danielrearden
Copy link
Owner

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?

@unlight
Copy link
Author

unlight commented Jun 14, 2020

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.

@danielrearden
Copy link
Owner

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 {}

@unlight unlight changed the title Missing directives Missing directives (NestJS integration) Jun 14, 2020
@unlight
Copy link
Author

unlight commented Jun 15, 2020

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

typeDefs: typeDefs.loc!.source.body,

@danielrearden
Copy link
Owner

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

@danielrearden danielrearden added enhancement New feature or request and removed bug Something isn't working labels Jun 15, 2020
@danielrearden
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants