Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Allow child image sharp on arrays of images #90

Merged
merged 6 commits into from
Feb 27, 2020

Conversation

denisgoryaynov
Copy link
Contributor

@denisgoryaynov denisgoryaynov commented Nov 17, 2019

Right now it's not possible to query File properties on arrays of images, for example this results in an error:

{
  allStrapiArticle {
    edges {
      node {
        multipleImages {
          publicURL
          childImageSharp {
            ...
          }
        }
      }
    }
  }
}

this pull request fixes the issue by allowing to query a localFile field on arrays of images:

{
  allStrapiArticle {
    edges {
      node {
        multipleImages {
          localFile {
            publicURL
            childImageSharp {
               ...
            }
          }
        }
      }
    }
  }
}

@aramkoukia
Copy link

Nice. When will this be available?

@beve
Copy link

beve commented Nov 27, 2019

Really nice. Hope it will be merged.

@omerman
Copy link

omerman commented Dec 20, 2019

Any news on this??

@Naismith
Copy link
Contributor

Naismith commented Feb 2, 2020

@soupette this PR does not appear to work with childImageSharp plugin for optimizing images.

@soupette
Copy link
Contributor

soupette commented Feb 3, 2020

@Naismith do you suggest to close it?

@denisgoryaynov
Copy link
Contributor Author

@Naismith did you find any issues? I'm currently using this version on my company's website with no problems but there may be some use cases I didn't consider when modifying the code, I can take a look and try to fix the issues if you have any feedback

@Naismith
Copy link
Contributor

Naismith commented Feb 3, 2020

@denisgoryaynov when looking at Gatsby's __graphql route, the images did not seem to have a localFile key, so I was unable to use the childImageSharp plugin on the images. I will test again tonight to make sure I didn't do anything wrong. @soupette would you confirm if you have any issues?

@denisgoryaynov
Copy link
Contributor Author

@Naismith I don't know if this is the case, but the localFile key exists only on arrays of images, when using a single image you can access fields like publicURL directly from the image

allStrapiArticle {
  nodes {
    SingleImage {
      publicURL
    }
    MultipleImages {
       localFile {
         publicURL
       }
    }
  }
}

@Naismith
Copy link
Contributor

Naismith commented Feb 4, 2020

Just tested again, it seems to be working fine for me now. I do wonder if there's a way we can do this without the 'localFile'. So that we can have a similar API with multipleImages as we do with singleImages.

But if @soupette is cool with how the current API is for multiple images, then I say it's good.

@11qu1d
Copy link

11qu1d commented Feb 16, 2020

This is a great feature and should be merged when its ready and tested, but when i was trying out the new versions i started getting errors when running gatsby develop and could not pull any info from Strapi:

 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "<my-field-name>" on type "Query".

Now, i am not an expert and this could be something i am doing wrong but here is what i saw:

  1. Uninstall the existing gatsby-source-strapi module:
    npm uninstall gatsby-source-strapi
  2. Install the new version from the forked repo:
    npm install --save https://github.com/denisgoryaynov/gatsby-source-strapi
  3. Try to run gatsby develop and get the above errors.

When i reverted the change and went back to version 0.0.10, everything stated working again.

Any suggestions are welcome :)

@denisgoryaynov
Copy link
Contributor Author

@likw1d the master branch of my fork is missing the compiled files that you would normally have when installing gatsby-source-strapi from npm, for now you can just add this line to your package.json:

"gatsby-source-strapi": "https://github.com/denisgoryaynov/gatsby-source-strapi.git#build",

and then run npm i. All this does is pulling the files from the 'build' branch which has the required files to make the plugin work.

@11qu1d
Copy link

11qu1d commented Feb 16, 2020

Thank you @denisgoryaynov, i just tried it again following your suggestion and works like a charm!

Copy link
Contributor

@soupette soupette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thanks a lot for your contribution!

I'll try to make a release soon!

@Mcastres Mcastres assigned Mcastres and unassigned Mcastres Feb 17, 2020
@Mcastres Mcastres self-requested a review February 17, 2020 09:29
@soupette
Copy link
Contributor

@Naismith Let's release it!

@soupette soupette merged commit eada801 into gatsby-uc:master Feb 27, 2020
@joe-thong
Copy link

when are we tagging a 0.11 release? can't seem to install straight from yarn add https://github.com/strapi/gatsby-source-strapi.git.

Constantly getting
Cannot query field "allStrapiPost" on type "Query".

Using
yarn add https://github.com/denisgoryaynov/gatsby-source-strapi.git#build instead for now

Thanks @denisgoryaynov for your work

@mfuezesi
Copy link

This issue is still present.

Thanks to @denisgoryaynov, your solution works great!

@jossydeleon
Copy link

Thanks @denisgoryaynov Working like a charm, I had to use your forked version because this problem still persist on current version 0.12

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.