benada002 / wp-graphql-widgets

This plugin adds widgets and sidebar queries to WPGraphQL.
13 stars 4 forks source link

Error 500 in production environment #2

Closed idesignzone closed 3 years ago

idesignzone commented 3 years ago

Hello. I have been using sidebar query to get the widgets from WP. Everything works fine in the local environment and I can successfully develop and build my project. However after migrating to live server I start getting error wherever I have queried the sidebars. Error: Response not successful: Received status code 500

this is my query

  sidebar(sidebar: PRIMARY) {
    id
    name
    widgets {
      edges {
        node {
          id
          html
        }
      }
    }
  }

I can still query sidebars and widgets in GraphQL IDE on live server but cant query it in my project. Live website is exact copy of my local website. I recreated another copy of the live website locally and everything works again. This problem happens only after going live. Wondering if you have tried the plugin in production environment. Any hints will be very helpful.

benada002 commented 3 years ago

I don't got time today, but I'll definitely take a look at it.

benada002 commented 3 years ago

How do you fetch the graphql api (axois, fetch, apollo...)? I tried around a bit and for me it came down to a cors issue.

idesignzone commented 3 years ago

This is pretty strange and I am not sure how to debug this. but this is the situation: I use Gridsome in front. When I build the app, building process pauses when it gets to sidebar query, During this pause I try to open live website and it gives me a database connection error, then build fails with 500 error. It seems the sidebar query breaks the database connection and fails.

benada002 commented 3 years ago

Are you using @gridsome/source-graphql to query? Which wp-graphql version are you on? How are building, on your local machine (from the live server)?

idesignzone commented 3 years ago

Are you using @gridsome/source-graphql to query? Which wp-graphql version are you on? How are building, on your local machine (from the live server)?

yes I use @gridsome/source-graphql and latest version of WPGraphQL.

I just place the live website URL (process.env.WORDPRESS_URL)

  plugins: [
    {
      use: '@gridsome/source-graphql',
      options: {
        url: (process.env.WORDPRESS_URL) + "/graphql",
        fieldName: 'WordPress',
        typeName: '',

        // headers: {
        //   Authorization: `Bearer ${process.env.AUTH_TOKEN}`,
        // },
      },
    },
    {
      use: 'gridsome-plugin-uikit'
    }
  ],
benada002 commented 3 years ago

Yeah that's indeed pretty strange. I just ran a gridsome build on my local machine with a live server, for me it worked just fine (just some posts and a basic sidebar). Do you maybe have any not standart widgets?

benada002 commented 3 years ago

Could it also be that a query before the sidebar query breaks, which causes the break of the database connection, and then leads to the 500 in the sidebar query?

idesignzone commented 3 years ago

Could it also be that a query before the sidebar query breaks, which causes the break of the database connection, and then leads to the 500 in the sidebar query?

Project is pretty big with many queries. I will try to query one by one to hopefully find the query that breaks the connection. Really appreciate your help. This plugin is great and you are awesome. I will update my investigation here. Thanks again.

benada002 commented 3 years ago

I could also send you the repo I created (and used) to test.

idesignzone commented 3 years ago

How do you fetch the graphql api (axois, fetch, apollo...)? I tried around a bit and for me it came down to a cors issue.

How did you manage to fix cors problem?

benada002 commented 3 years ago

For fetch (and apollo in the frontend) with credentials: "omit". But since @gridsome/source-graphql uses apollo and node-fetch it shouldn't be a problem because credentials is not implemented in node-fetch (https://github.com/node-fetch/node-fetch#class-request).

idesignzone commented 3 years ago

I can still develop and build the project locally but I found it difficult to debug 500 error . Build is breaking the server on a sidebar query but after excluding sidebar queries I still get the error. I believe we can close this issue as it doesn't relate to this plugin. Thanks for checking on this issue.

benada002 commented 3 years ago

No problem. Just out of curiosity, is gridsome develop working with the live server as the data source?