Giter Club home page Giter Club logo

Comments (18)

viperfx avatar viperfx commented on June 4, 2024 1

Oh right! That fixed it!

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

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024 1

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

from gatsby-plugin-groq.

kmcaloon avatar kmcaloon commented on June 4, 2024

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?

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024

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

from gatsby-plugin-groq.

kmcaloon avatar kmcaloon commented on June 4, 2024

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?

from gatsby-plugin-groq.

kmcaloon avatar kmcaloon commented on June 4, 2024

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.

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024

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

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024

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.

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024

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

from gatsby-plugin-groq.

kmcaloon avatar kmcaloon commented on June 4, 2024

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.

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024
{"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`"}

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024

No further errors below

from gatsby-plugin-groq.

kmcaloon avatar kmcaloon commented on June 4, 2024

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;

from gatsby-plugin-groq.

kmcaloon avatar kmcaloon commented on June 4, 2024

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

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024

Yep - it working for me now. Thanks!

from gatsby-plugin-groq.

viperfx avatar viperfx commented on June 4, 2024

@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.

from gatsby-plugin-groq.

kmcaloon avatar kmcaloon commented on June 4, 2024

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 ]

from gatsby-plugin-groq.

kmcaloon avatar kmcaloon commented on June 4, 2024

@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.

from gatsby-plugin-groq.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.