question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ExpressionAttributeValues must not be empty in graphQL with Gatsby

See original GitHub issue

Description

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.

###[./src/pages/profile.js]

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

###[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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
vladarcommented, Nov 5, 2020

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! 💜

1reaction
vladarcommented, Nov 2, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - ExpressionAttributeValues must not be empty in ...
But am getting Validation Exception stating ExpressionAttributeValues must not be empty. Iam just assigning the interface to vehicleInfo
Read more >
Troubleshooting Common Errors - Gatsby
This error message Field "image" must not have a selection since type "String" has no subfields. comes up when a GraphQL query is...
Read more >
Handle empty results in a Gatsby source plug-in | Anton Ball
I don't understand how and the build fails because the query has no results. Do you create an empty node in Graphql? Is...
Read more >
GatsbyJS + Drupal: Create Custom GraphQL Schema for ...
For the remainder of this post I will refer to GraphQL nodes as "nodes" and Drupal ... However, empty data in the source...
Read more >
Gatsby, GraphQL and the Missing But Necessary Explanation ...
This works perfectly when all the data that has been queried and all your fields are filled with non-empty data, if we have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found