craftcms / gatsby-helper

Craft CMS helper plugin for Gatsby.
https://plugins.craftcms.com/gatsby-helper
MIT License
15 stars 6 forks source link

Does this only work when in Headless Mode? #8

Closed SamJamWillingham closed 3 years ago

SamJamWillingham commented 3 years ago

Description

I am working on a project that is essentially taking an existing templated Craft website and creating new Gatsby front-end. The existing website is not in Headless mode yet while the new front end is still in development.

Does craft have to be in headless mode for these plugins to work? I ask because I'm getting these errors while trying to connect the API to the existing (not headless) CMS and I read in the craft documentation that the API responses are in HTML unless in headless mode where the responses will then be in json.

FetchError: invalid json response body at https://[REDACTED].com/api/ reason: Unexpected token   in JSON at position 0

  - index.js:272 
    [REDACTED]/[node-fetch]/lib/index.js:272:32

  - task_queues.js:93 processTicksAndRejections
    internal/process/task_queues.js:93:5

  - gatsby-node.js:287 execute
    [REDACTED]/[gatsby-source-craft]/gatsby-node.js:287:12

  - load-schema.ts:12 introspectSchema
    [REDACTED]/[gatsby-graphql-source-toolkit]/src/config/load-schema.ts:12:31

  - load-schema.ts:36 loadSchema
    [REDACTED]/[gatsby-graphql-source-toolkit]/src/config/load-schema.ts:36:31

  - gatsby-node.js:38 getSchema
    [REDACTED]/[gatsby-source-craft]/gatsby-node.js:38:18

  - gatsby-node.js:208 writeDefaultFragments
    [REDACTED]/[gatsby-source-craft]/gatsby-node.js:208:17

  - gatsby-node.js:542 ensureFragmentsExist
    [REDACTED]/[gatsby-source-craft]/gatsby-node.js:542:5

  - gatsby-node.js:305 Object.exports.onPreBootstrap
    [REDACTED]/[gatsby-source-craft]/gatsby-node.js:305:5

  - api-runner-node.js:483 runAPI
    [REDACTED]/[gatsby]/src/utils/api-runner-node.js:483:16

Steps to reproduce

1. 2.

Additional info

andris-sevcenko commented 3 years ago

Have you set up the route you're using? (/api) Are you using the right token for access or, if not using a token, is the Public Schema configured to allow Gatsby queries?

SamJamWillingham commented 3 years ago

I have my endpoint set up to /api, and I am using a private schema with the token in my gatsby config.

andris-sevcenko commented 3 years ago

Okay, next thing to check would be Craft CMS log files - GraphQL API responses are always in JSON, so it's possible that you're hitting a PHP error and there's a stack trace in the response, which should also get logged to the log files.

SamJamWillingham commented 3 years ago

I'm very new to Craft-- are the log files the same ones that you can reach via the dashboard > utilities > logs ? Or are they stored in the database?

andris-sevcenko commented 3 years ago

They are stored on the server - storage/logs/ and you would be interested in both phperrors.log (if it exists) and web.log.

SamJamWillingham commented 3 years ago

I went through both phperrors and web and didn't see any trace of my failed API call

andris-sevcenko commented 3 years ago

That is odd. Are you able to query the API using the same token with a client, for example, Insomnia?

SamJamWillingham commented 3 years ago

Screen Shot 2021-04-08 at 10 39 08 AM

So I'm getting the same error message in Insomnia. I tried reading through the timeline tab but I am struggling to understand enough to find where it went wrong. (I didn't block out or censor anything in the preview window. Its just blank)

Not to get too confusing but this project is migrating an existing create-react-app website to Gatsby. In the first React version, obviously being client side rendering, I used ApolloClient and would get the response below. But now using Gatsby and their source plugin, I'm running into this problem. Hope some context is helpful? Screen Shot 2021-04-08 at 10 47 36 AM

andris-sevcenko commented 3 years ago

Well, the good news is that it's reproducable from an "external" request. Is this in a publicly reachable site, somewhere? If so, is it possible to share the Gatsby token via email with support@craftcms.com? I could try to unravel this for you then.

If you can do that, please reference this issue. If this is not on a public site, I'll think on some options on how to make it easer to debug this.

Sorry for all the hassle!

andris-sevcenko commented 3 years ago

Closing due to inactivity.