Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String interpolation/concat on Graphql Queries #5090

Closed
ThiagoMiranda opened this issue Apr 23, 2018 · 2 comments
Closed

String interpolation/concat on Graphql Queries #5090

ThiagoMiranda opened this issue Apr 23, 2018 · 2 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@ThiagoMiranda
Copy link

ThiagoMiranda commented Apr 23, 2018

Hi...
I'm trying to make a search and concatenate an variable with some surround string to work with the regex filter. How can I do that in Graphql? My goal is to wrap the $lang variable in / characters. Somehthing like that ( this don´t work ):

  query ContentByPath($slug: String!, $lang: String!) {
    site {
      siteMetadata {
        title
      }
    }
    markdownRemark(
      frontmatter: { slug: { eq: $slug } }, fileAbsolutePath: { regex: "/${$lang}/" }) {
      id
      htmlAst
      html
      frontmatter {
        section
        title
        date(formatString: "MMMM DD, YYYY")
      }
    }
  }

Is it possible?

Thanks

@m-allanson
Copy link
Contributor

@ThiagoMiranda this isn't supported at the moment, but there's some discussion at #5069 and an RFC at gatsbyjs/rfcs#3.

@m-allanson m-allanson added the type: question or discussion Issue discussing or asking a question about Gatsby label Apr 24, 2018
@julionav
Copy link

julionav commented Mar 3, 2020

I know this is closed but when googling how to do interpolation in gatsby this still shows up.

The workaround that I did for this is to construct the regex expression outside the graphql query.

In my case, it was inside createPages inside gatsby-node

context: {
  moduleRegex: `/${module}/`,
}

Then inside the query:

query($moduleRegex: String, $mdxId: String) {
    mdx(id: { eq: $mdxId }) {
      body
    }
    allFile(filter: { relativeDirectory: { regex: $moduleRegex } }) {
      nodes {
        name
      }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants