Closed viperfx closed 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?
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
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?
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.
So just an update, my query does work with the react hook you provided.
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.
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
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.
{"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`"}
No further errors below
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;
Oh right! That fixed it!
Well now I am wondering how my other gatsby pages are working :)
Hey @viperfx, how did everything work out? Can I close this?
Yep - it working for me now. Thanks!
@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.
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 ]
Yep that works! Thanks. Yep def something to note with examples, easy to trip up on without know the internals.
@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.
Got the following stack trace when running
yarn start
on a sanity/gatsby project