GraphQL: Warning: Failed prop type: Invalid prop `query` of type `object` supplied to `StaticQuery`, expected `string`

Galanthus

I am working on my Gatsby website. But I am facing a weird problem where when visiting a single blog post I get the following error for my Query:

index.js:2177 Warning: Failed prop type: Invalid prop `query` of type `object` supplied to `StaticQuery`, expected `string`.
    in StaticQuery (at Layout.jsx:35)
    in Layout (at post.jsx:136)
    in Post (at post.jsx:164)
    in _default (created by HotExported_default)
    in AppContainer (created by HotExported_default)
    in HotExported_default (created by PageRenderer)
    in WrapPage (created by PageRenderer)
    in PageRenderer (at query-result-store.js:86)
    in PageQueryStore (at root.js:56)
    in RouteHandler (at root.js:78)
    in div (created by FocusHandlerImpl)
    in FocusHandlerImpl (created by Context.Consumer)
    in FocusHandler (created by RouterImpl)
    in RouterImpl (created by Context.Consumer)
    in Location (created by Context.Consumer)
    in Router (created by EnsureResources)
    in ScrollContext (at root.js:69)
    in RouteUpdates (at root.js:68)
    in EnsureResources (at root.js:66)
    in LocationHandler (at root.js:124)
    in LocationProvider (created by Context.Consumer)
    in Location (at root.js:123)
    in Root (at root.js:132)
    in StaticQueryStore (at root.js:138)
    in _default (at app.js:67)

My Layout.jsx:

const Layout = ({ children }) => (
  <StaticQuery
    query={graphql`
      query SiteTitleQuery {
        site {
          siteMetadata {
            title
          }
        }
      }
    `}
    render={data => (
      <LayoutContainer className="div">
        <Global styles={[globalStyles, typeStyles]} />
        <div className="Layout">
          <Header />
          <main className="Layout__content">{children}</main>
          <Footer />
        </div>
      </LayoutContainer>
    )}
  />
)

Layout.propTypes = {
  children: PropTypes.node.isRequired,
}

export default Layout

Why am I getting this error :)? I am trying to fix this but without luck. Hopefully, someone can help me out.

ksav

Possibly due to a bug in StaticQuery. There is a potential workaround in a similar issue here.

Try to pull the query out, wrap it in a template string before passing it to StaticQuery's query param.

    const myStaticQuery = graphql`
    query SiteTitleQuery {
      site {
        siteMetadata {
          title
        }
      }
    }
  `

    const Layout = ({ children }) => (
      <StaticQuery
        query={`${myStaticQuery}`}
        render={data => (
          <LayoutContainer className="div">
            <Global styles={[globalStyles, typeStyles]} />
            <div className="Layout">
              <Header />
              <main className="Layout__content">{children}</main>
              <Footer />
            </div>
          </LayoutContainer>
        )}
      />
    )

    Layout.propTypes = {
      children: PropTypes.node.isRequired,
    }

    export default Layout

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Warning: Failed prop type: Invalid prop `items[0]` of type `string` supplied to `ImageGallery`, expected `object`

React Warning: Failed prop type: Invalid prop of type `Object` supplied

Warning: Failed prop type: Invalid prop `data` of type `object` supplied to `Carousel`, expected `array`

Warning: Failed prop type: Invalid prop `value` of type `number` supplied to `TextInput`, expected `string`

Warning: Failed prop type: Invalid prop `defaultValue` of type `string` supplied to `AutoCompleteSearch`, expected `function`

Failed prop type: Invalid prop `match.params` of type `object` supplied to `Page`, expected `string`

Failed prop type: Invalid prop `children` of type `string` supplied to `DetailField`, expected `object`

Failed prop type: Invalid prop `answer` of type `string` supplied to `AnswerItem`, expected `object`

Warning: Failed prop type: Invalid prop `open` of type `function` supplied to `ForwardRef(Dialog)`, expected `boolean`. at Dialog

Warning: Failed prop type: Invalid prop `tag` supplied to `NavLink`

Warning: Failed prop type: Invalid prop 'source' supplied to 'Image'

warning: failed prop type: invalid prop 'backgroundcolor' supplied to view:

GETTING ERROR : Warning: Failed prop type: Invalid prop `children` supplied to `Form`, expected a ReactNode

Warning: Failed prop type: Invalid prop `children` supplied to `ForwardRef(Select)`, expected a ReactNode

Failed prop type: Invalid prop `opacity` of type `object` supplied to `RCTView`

Failed prop type: Invalid prop `onClick` of type `object` supplied to `ButtonBase`, expected `function`

Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function`

Why do I get Failed prop type: Invalid prop `onAnimationFinish` of type `object` supplied to `LottieView`, expected a `funtion`

Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function`

Failed prop type: Invalid prop `responsive` of type `string` supplied to `Image`, expected `boolean`

Warning: Failed prop type: Invalid prop `source` supplied to `Image`. I have saved path of the image with require() in an object

Warning: Failed propType: Invalid prop of type `array` expected `object` with React

Failed prop type: Invalid prop `to` supplied to `Redirect`

How to Solve ERROR Warning: Failed prop type: Invalid prop `style` of type `array` supplied to `Row`, expected `object` (react-native-table-component)

Invalid prop `component` of type `object` supplied to `Route`, expected `function`

Invalid prop: type check failed for prop "cellClass". Expected String with value "[object Object]", got Object

[Vue warn]: Invalid prop: type check failed for prop "productCartData". Expected Object, got String with value "[object Object]"

Failed prop type: Invalid prop of type `function` supplied expected a single ReactElement

Invalid prop type supplied