sqlmancer
sqlmancer copied to clipboard
Missing directives (NestJS integration)
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);
Looks like it's not all from https://sqlmancer.netlify.app/directives
At least model
, sqlmancer
are missing.
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?
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.
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 {}
Thank you, that's worked.
But NestJS's GraphQLModule typeDefs
expects string
typeDefs: typeDefs.loc!.source.body,
@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.
It would also be worthwhile to document NestJS integration alongside any other commonly-used libraries