progital / gatsby-wpgraphql-inline-images

Solution for Gatsby and WPGraphQL sourced content. Downloads images locally.
MIT License
35 stars 12 forks source link

Package doesn't appear to be working with query hooks #17

Closed alex-troyer closed 4 years ago

alex-troyer commented 4 years ago

import { useStaticQuery, graphql } from 'gatsby'

export const useContentPlaceholder = () => { const { wpgraphql } = useStaticQuery(graphql query useContentPlaceholderQuery { wpgraphql { post(id: "cG9zdDoxMzM=") { content } } } )

return wpgraphql.post.content

}

import React from 'react' import contentParser from 'gatsby-wpgraphql-inline-images' import { useContentPlaceholder } from '../../hooks/useContent'

export default () => { const content = useContentPlaceholder()

const pluginOptions = {
  wordPressUrl: `https://noh.progital.dev/`,
  uploadsUrl: `https://noh.progital.dev/wp-content/uploads/`,
}
return (
    <React.Fragment>
        {<div>{contentParser({ content }, pluginOptions)}</div>}
    </React.Fragment>
)

}

I test across multiple different wordpress domains and even the example domain provided and the inline images are not being saved locally and converted into gatsby images. Am I doing something wrong here?

alex-troyer commented 4 years ago

here is the config file

module.exports = { siteMetadata: { title: Gatsby Default Starter, description: Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need., author: @gatsbyjs, }, plugins: [ gatsby-plugin-react-helmet, { resolve: gatsby-source-filesystem, options: { name: clients, path: ${__dirname}/src/images/clients/logos, }, }, { resolve: gatsby-source-filesystem, options: { name: images, path: ${__dirname}/src/images, }, }, gatsby-transformer-sharp, gatsby-plugin-sharp, { resolve: gatsby-plugin-manifest, options: { name: gatsby-starter-default, short_name: starter, start_url: /, background_color: #93c9e3, theme_color: #93c9e3, display: minimal-ui, icon: src/images/logo/logo-dark.png, // This path is relative to the root of the site. }, }, { resolve: gatsby-plugin-styled-components, options: { displayName: false }, }, { resolve: gatsby-plugin-prefetch-google-fonts, options: { fonts: [ { family: Open Sans, variants: [300, 400, 700, 800] }, ], }, }, 'gatsby-plugin-workerize-loader', { resolve: "gatsby-source-graphql", options: { typeName: "WPGraphQL", fieldName: "wpgraphql", url: "https://noh.progital.dev/graphql", }, }, { resolve: 'gatsby-wpgraphql-inline-images', options: { wordPressUrl: https://noh.progital.dev/, uploadsUrl: https://noh.progital.dev/wp-content/uploads/, processPostTypes: ['Post'], graphqlTypeName: 'WPGraphQL', }, }, ], }

progital commented 4 years ago

Could try adding debugOutput set to true to the plugin options in the config file? Let's see what's there.

MichalKotowski commented 4 years ago

Hello! I think that I have the same problem as troyersolutions. After adding debugOutput it returns >>> Entered contentResolver @ URI not defined, skipping inside console panel. If it might help, here is my template file structure:

const BlogPostTemplate = ({ data }) => {
    const content = data.wpgraphql.post.content
    const wordPressUrl = `http://nerdcow.laohost.net/`
    const uploadsUrl = `http://nerdcow.laohost.net/wp-content/uploads/`
    return (
        <Layout>
            <h1 dangerouslySetInnerHTML={{ __html: data.wpgraphql.post.title }} />
            <div>{contentParser({ content }, { wordPressUrl, uploadsUrl })}</div>
        </Layout>
    )
}

export default BlogPostTemplate

export const query = graphql`
    query GET_POST($id: ID!) {
        wpgraphql {
            post(id: $id) {
                content
                title
            }
        }
    }
`

I really appreciate your hard work and that you're willing to help everyone that posts in issues! I'm trying to fix it by myself, but as time go I'm losing all hope.

MichalKotowski commented 4 years ago

Hi, Could you try adding uri to all your queries that fetch content? It won't work without uri in the query.

This answer of yours from the other topic helped me, thanks!

progital commented 4 years ago

Yeah, this is something that is not documented because I wanted to look if I could drop this requirement. Probably should just add this to docs for now.

progital commented 4 years ago

Done f4604e39fc0d8c8cb3a1af3600af9de237e272ad