You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Me again! Thanks for the incredibly rapid response to my last two issues - hopefully this is the last for a while ... 馃槃 )
So in my app I am using the typeDefs config option and omitting typePaths because I do some of my own pre-processing of the schema files before handing them off to Nest.
There is an issue currently with this part of the GraphQLModule code:
When this.options.typePaths is falsy (undefined in my case), then the call to this.graphQLFactory.mergeTypesByPath() will return the following string:
schema {
query: Query
}
When this is later combined with the string I pass as the typeDefs value, then the resulting schema only contains my Queries, but none of my Mutations.
Expected behavior
Passing typeDefs and no typePaths should result in a schema exactly equivalent to that defined by the typeDefs string.
Minimal reproduction of the problem with instructions
git clone git@github.com:nestjs/nest.git
cd nest/sample/12-graphql-apollo
npm install
edit app.module.ts to look like:
GraphQLModule.forRootAsync({useFactory(){return{installSubscriptionHandlers: true,typeDefs: ` type Query { getCats: [Cat] cat(id: ID!): Cat } type Mutation { createCat(name: String): Cat } type Subscription { catCreated: Cat } type Cat { id: Int name: String age: Int } `};},}),
npm run start
When trying to execute the createCat mutation, you will not get the error: "Schema is not configured for mutations."
Additional note: I noticed when putting together the reproduction that when passing the above config to the .forRoot() method, the app does not even bootstrap, instead failing with the error:
UnhandledPromiseRejectionWarning: Error: Type "Query" was defined more than once.
at Object.buildASTSchema (C:\Development\temp\nest\sample\12-graphql-apollo\node_modules\graphql\utilities
What is the motivation / use case for changing the behavior?
Sometimes you need to pre-process the typedefs before handing off to Nest. In my case, I use user config to create custom fields at run-time.
Suggested fix
I fixed the issue locally by changing line 100 to:
I'm submitting a...
Current behavior
(Me again! Thanks for the incredibly rapid response to my last two issues - hopefully this is the last for a while ... 馃槃 )
So in my app I am using the
typeDefs
config option and omittingtypePaths
because I do some of my own pre-processing of the schema files before handing them off to Nest.There is an issue currently with this part of the
GraphQLModule
code:graphql/lib/graphql.module.ts
Lines 100 to 106 in 304c1fe
When
this.options.typePaths
is falsy (undefined in my case), then the call tothis.graphQLFactory.mergeTypesByPath()
will return the following string:When this is later combined with the string I pass as the
typeDefs
value, then the resulting schema only contains my Queries, but none of my Mutations.Expected behavior
Passing
typeDefs
and notypePaths
should result in a schema exactly equivalent to that defined by thetypeDefs
string.Minimal reproduction of the problem with instructions
git clone git@github.com:nestjs/nest.git
cd nest/sample/12-graphql-apollo
npm install
npm run start
When trying to execute the
createCat
mutation, you will not get the error: "Schema is not configured for mutations."Additional note: I noticed when putting together the reproduction that when passing the above config to the
.forRoot()
method, the app does not even bootstrap, instead failing with the error:What is the motivation / use case for changing the behavior?
Sometimes you need to pre-process the typedefs before handing off to Nest. In my case, I use user config to create custom fields at run-time.
Suggested fix
I fixed the issue locally by changing line 100 to:
Environment
The text was updated successfully, but these errors were encountered: