I'm using Gatsby with the below plugin.
"gatsby": "^2.21.0",
"gatsby-source-graphql": "^2.7.6",
When I use GraphQL, I got this error. I researched a solution, I couldn't any hints.
ExpressionAttributeValues must not be empty (Service: DynamoDb, Status Code: 400, Request ID: 8A2PS0BPLA5RB1869L21ONB0NJVV4KQNSO5AEMVJF66Q9ASUAAJG, Extended Request ID: null)
The GraphQL is below.
.....
export const query = graphql`
query GetSingleProfile($slug: String) {
DynamoDB {
listBlrUsermatchs(filter: {slug: {eq: $slug}}) {
items {
id
imgUrl
imgUrlS3
kinds
languagesSpoken
location
name
.......
}
}
}
}
`
.....
I have below in gatsby-node.js.
const usermatches = await graphql(`
{
usermatches: DynamoDB {
listBlrUsermatchs {
items {
slug
state
city
category
}
}
}
}
`)
usermatches.data.usermatches.listBlrUsermatchs.items.forEach(data => {
// Make Category
var category = '';
data.category.map((p) => {
category = category + '-' + p;
})
const state = data.state[0].replace(' ', '-').toLowerCase();
const city = data.city.replace(' ', '-').toLowerCase();
category = category.substring(1);
const uri = category + '/' + state + '/' + city + '/' + data.slug;
createPage({
path: `/${uri}`,
component: path.resolve(`./src/pages/profile.js`),
context: {
slug: data.slug
},
});
});
I want to pash a 'slug' that is defined in getsby-node.js tho, it might cause the problem. When I use a fixed value (like a 'programer' ) instead of $slug in profile.js, it goes well. And also, although I get the error, the program works.
Have you tried running the same query against your remote GraphQL endpoint directly (with slug as a variable):
query DynamoDB($slug: String) {
listBlrUsermatchs(filter: {slug: {eq: $slug}}) {
items {
id
imgUrl
imgUrlS3
kinds
languagesSpoken
location
name
}
}
}
I am a bit suspicious about the filter part here: listBlrUsermatchs(filter: {slug: {eq: $slug}}). It looks like a Gatsby filter.
Also to clarify: the error you've posted comes from your remote GraphQL API not from Gatsby, that's why I am asking.
I tried it on a remote server tho, it worked. The code is below.
query MyQuery($slug: String) {
listBlrUsermatchs(filter: {slug: {eq: $slug}}) {
items {
id
imgUrl
imgUrlS3
kinds
languagesSpoken
location
name
}
}
}
variable
{
"slug": "test"
}
Hi @uekyo !
This sounds pretty weird. But it's hard to help without having some code to look at.
It is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.
If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.
Thanks for using Gatsby! 馃挏
Hi @valdar!
Okay, I'm going to do that. Please wait for a little while longer.
Hey @vladar
I uploaded the Minimal Reproduction here.
https://gitlab.com/kyo.ueda/bug-repro-gatsby-slug
It's the first time to use GitLab to publish the code tho, if you need more information let me know please.
Kyo
I never worked with DynamoDB. Do you have any demo endpoint to test against?
It's fine. I sent the complete code by email just now.
Kyo
Thank you for opening this, @uekyo
The problem is that you've placed your template in src/pages folder: https://gitlab.com/kyo.ueda/bug-repro-gatsby-slug/-/blob/master/src/pages/places.js
Gatsby creates pages for all files in src/pages folder automatically. But it executes queries from those files without any variables. And that's why you see this error. If you move your template file from src/pages/places.js to src/templates/places.js and update the path in createPages API it works as expected.
We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 馃挏
I did it! Thank you so much!馃槶
Most helpful comment
Thank you for opening this, @uekyo
The problem is that you've placed your template in
src/pagesfolder: https://gitlab.com/kyo.ueda/bug-repro-gatsby-slug/-/blob/master/src/pages/places.jsGatsby creates pages for all files in
src/pagesfolder automatically. But it executes queries from those files without any variables. And that's why you see this error. If you move your template file fromsrc/pages/places.jstosrc/templates/places.jsand update the path increatePagesAPI it works as expected.We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 馃挏