kmcaloon / gatsby-plugin-groq

Gatsby plugin for using GROQ in place of GraphQL
MIT License
36 stars 2 forks source link

Cannot find module 'gatsby-cli/lib/reporter' #1

Closed viperfx closed 4 years ago

viperfx commented 4 years ago

Got the following stack trace when running yarn start on a sanity/gatsby project

gatsby_1  |   Error: Cannot find module 'gatsby-cli/lib/reporter'
gatsby_1  |   Require stack:
gatsby_1  |   - /code/web/plugins/gatsby-plugin-groq/gatsby-node.js
gatsby_1  |   - /code/web/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
gatsby_1  |   - /code/web/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
gatsby_1  |   - /code/web/node_modules/gatsby/dist/bootstrap/load-plugins/load.js
gatsby_1  |   - /code/web/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
gatsby_1  |   - /code/web/node_modules/gatsby/dist/bootstrap/index.js
gatsby_1  |   - /code/web/node_modules/gatsby/dist/commands/develop.js
gatsby_1  |   - /code/web/node_modules/gatsby/node_modules/gatsby-cli/lib/create-cli.js
gatsby_1  |   - /code/web/node_modules/gatsby/node_modules/gatsby-cli/lib/index.js
gatsby_1  |   - /code/web/node_modules/gatsby/dist/bin/gatsby.js
kmcaloon commented 4 years ago

Thanks for the heads up. This should be resolved with the latest release. Can you remove the local plugin and install the new npm package and let me know if it resolves the issue?

viperfx commented 4 years ago

Thanks for the reply!

@kmcaloon I tried 1.0.0-alpha.1

With the following query and the

export const groqQuery = `
{
    "agileTemplates": *[_type == "reportTemplate" && category == "Agile"]{
        category,
        content,
        isFeatured,
        "currentSlug": slug.current,
        summary,
        title,
        "relatedTemplates": related[]->{title,summary, "currentSlug":slug.current}
    },
    "productivityTemplates": *[_type == "reportTemplate" && category == "Productivity"]{
        category,
        content,
        isFeatured,
        "currentSlug": slug.current,
        summary,
        title,
        "relatedTemplates": related[]->{title,summary, "currentSlug":slug.current}
    }
}

pages/templates.js

const TemplatesPage = props => {
  const { data, errors } = props
  console.log(data, errors)
  if (errors) {
    return (
      <Layout>
        <GraphQLErrorList errors={errors} />
      </Layout>
    )
  }

The data var is undefined in console

kmcaloon commented 4 years ago

Thanks for bearing with this as the plugin is being built out and tested! Can you do me a favor and paste the full terminal output after you run gatsby develop?

kmcaloon commented 4 years ago

Oh I also noted one thing with your query. I know I mentioned in the README that joins were somewhat limited, but I just realized I didn't specify how.

Right now for everything other than assets like images we can't use joins with the -> operator. There are reasons for this and I touched base with the Sanity team about the limitation, but for now we have to use the more verbose patterns they give in the docs.

Assuming this is based off of a dataset from Sanity, instead of this:

"relatedTemplates": related[]->{title,summary, "currentSlug":slug.current}

You would want something like this:

"relatedTemplates": *[ _type == "reportTemplate" && _id in ^.relatedTemplates[]._ref ]{
  title,
  summary,
  "currentSlug": slug.current
}

First we'll clear up the original issue and then make sure we get that query to work.

viperfx commented 4 years ago

So just an update, my query does work with the react hook you provided.

viperfx commented 4 years ago

When running the dev server, there is no specific output related to this plugin or any errors. When using export const groqQuery I just know the query is not returning any results and the var is undefined.

viperfx commented 4 years ago

Actually I found some relevant logs

success source and transform nodes - 1.947s
warn On types with the `@dontInfer` directive, or with the `infer` extension set to `false`, automatically adding fields for children types is deprecated.
In Gatsby v3, only children fields explicitly set with the `childOf` extension will be added.
For example, in Gatsby v3, `SanityImageAsset` will not get a `childImageSharp` field.
success building schema - 0.427s
info [groq] Getting files for groq extraction...
info [groq] Caching page query: 1316704189
success [groq] Finished getting files for query extraction
kmcaloon commented 4 years ago

Hmm but no error messages a little further down right before createPages is finished? Would you be able to paste a copy of that cached query? It should be located in .cache/groq/1316704189.json under your project root.

viperfx commented 4 years ago
{"unprocessed":"`\n{\n    \"agileTemplates\": *[_type == \"reportTemplate\" && category == \"Agile\"]{\n        category,\n        content,\n        isFeatured,\n        \"currentSlug\": slug.current,\n        summary,\n        title,\n        \"relatedTemplates\": *[ _type == \"reportTemplate\" && _id in ^.relatedTemplates[]._ref ]{\n          title,\n          summary,\n          \"currentSlug\": slug.current\n        }\n    },\n    \"productivityTemplates\": *[_type == \"reportTemplate\" && category == \"Productivity\"]{\n        category,\n        content,\n        isFeatured,\n        \"currentSlug\": slug.current,\n        summary,\n        title,\n        \"relatedTemplates\": *[ _type == \"reportTemplate\" && _id in ^.relatedTemplates[]._ref ]{\n          title,\n          summary,\n          \"currentSlug\": slug.current\n        }\n    }\n}\n`"}
viperfx commented 4 years ago

No further errors below

kmcaloon commented 4 years ago

Ahh I missed it in your code above. So the data property belongs to pageContext not Gatsby's default prop. This might be something that changes way down the road.

So in your template can you update this:

const { data, errors } = props;

To this:

const { pageContext: { data }, errors } = props;
viperfx commented 4 years ago

Oh right! That fixed it!

Well now I am wondering how my other gatsby pages are working :)

kmcaloon commented 4 years ago

Hey @viperfx, how did everything work out? Can I close this?

viperfx commented 4 years ago

Yep - it working for me now. Thanks!

viperfx commented 4 years ago

@kmcaloon

I am having an issue with the following query:

*[_type == "reportTemplate" && slug.current == $slug][0]{
    category,
    content,
    isFeatured,
    "currentSlug": slug.current,
    summary,
    title,
    scheduleType,
    questions,
    "relatedTemplates": *[ _type == "reportTemplate" && _id in ^.related[]._ref ]{
        title,
        summary,
        "currentSlug": slug.current
      }
}

In the vision plugin in studio, this query returns results for the relatedTemplates but in Gatsby, it returns empty.

Let me know if you would like me to open a new issue.

kmcaloon commented 4 years ago

Looks like I forgot to document this for people using Sanity. Right now the gatsby-source-sanity plugin changes the _refs to point to Gatsby's node ids instead of Sanity's _id field. When trying to query documents based on _refs, always use the id field instead of _id.

So try changing this:

"relatedTemplates": *[ _type == "reportTemplate" && _id in ^.related[]._ref ]

To this

"relatedTemplates": *[ _type == "reportTemplate" && id in ^.related[]._ref ]
viperfx commented 4 years ago

Yep that works! Thanks. Yep def something to note with examples, easy to trip up on without know the internals.

kmcaloon commented 4 years ago

@viperfx just a heads up, default joins are now enabled with the most recent update. I would look over the README to see how to configure everything.