English 中文(简体)
NestJs图图QL 出入游乐场
原标题:NestJs GraphQL playground access
I can t seem to access the GraphQL Playground using NestJS. I m exploring the documentation and have followed this https://docs.nestjs.com/graphql/quick-start up to the Resolvers section to generate the schema.gql, but attempting to reach localhost:3000/graphql is not able to connect. At first I thought my code was setup incorrectly, but I spent some time digging into Nest s examples and found that those also do not work when trying to access the /graphql endpoint. It does work if I setup a get endpoint to return a JSON body using the REST method. import { Module } from @nestjs/common ; import { GraphQLModule } from @nestjs/graphql ; import { RecipesModule } from ./recipes/recipes.module ; @Module({ imports: [ RecipesModule, GraphQLModule.forRoot({ installSubscriptionHandlers: true, autoSchemaFile: schema.gql , }), ], }) export class AppModule {} This is directly from the NestJS example. My understanding is that the GraphQLModule should be setting up the connection to the /graphql endpoint. Following the docs, graphql, apollo-server-express, and graphql-tools were all installed. Any idea why the graphql route is not connecting? [Edit]: Things I ve tried so far: setting playground: true explicitly with GraphQLModule.forRoot verified NODE_ENV is not production confirmed server works when creating resolvers using REST curl d localhost:3000/graphql and receive a graphql validation error, so confirm that connects correctly
最佳回答
Seems to be an issue with WSL2 running on Windows 10. This thread on github has some insight into the issue. Disable Fast Startup to allow access to localhost. https://github.com/microsoft/WSL/issues/5298
问题回答
sometimes helmet causes this same issue. if you have helmet loaded as a middleware, it might probably also cause this.
I encountered a similar issue this is what I did. I hope you will find it helpful. I appreciated everyone s support. Step1: // app.module.ts imports: [ UsersModule, GraphQLModule.forRoot({ // autoSchemaFile: true, did not work! autoSchemaFile: join(process.cwd(), src/schema.gql ), // schema.gql will automatically be created debug: true, playground: true, }), ], providers: [AppResolver], // all resolvers & service should be in providers step 2: Make sure you have one at least query bcz Mutation is not enough if you don t GraphQL playground will not start. Read more here
2 years late but found a simple workaround, since helmet was the issue too. Conditionally use helmet(), like this: process.env.CURRENT_ENV === dev && app.use(helmet()) Assuming CURRENT_ENV is a custom environment variable that I use instead of NODE_ENV.
Removing the dist folder and restarting the app worked for me.
Still have the same issue with helmet, I just checked the environment and used it conditionally, and it worked for me: const isGqlEnvProd = process.env.GQL_ENV === prod ; if(isGqlEnvProd){ app.use(helmet()); }




相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签