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.

How to use g-image with graphQL?

See original GitHub issue

It feels like we need a community somewhere to ask questions like mine here, but anyway. There seems to be some info missing in the documentation about g-image and how to use it with graphQL.

The section here https://gridsome.org/docs/images#usage-via-graphql does not state how to format the src link. So what should the link look like to work?

After a lot of googling and searching I got it working by writing it like this: <g-image :src="require(`!!assets-loader?width=552!@/${edge.node.image1}`)" width="552" /> But that was a very ugly way of doing it, so is there a nicer way to do this?

Issue Analytics

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

github_iconTop GitHub Comments

12reactions
hjvedvikcommented, Mar 31, 2019

Only local, relative image paths will be compressed when using g-image when the src attribute points to a local file like: <g-image src="../assets/image.jpg" />.

But when adding nodes to the GraphQL layer, you need to use an absolute file path. There are various methods for getting an absolute path like path.resolve, path.join or require.resolve:

{
  image1: require.resolve('./src/assets/images/my-image.jpg')
}
4reactions
hjvedvikcommented, Apr 1, 2019

I understand your concerns. We are trying to catch up features in other SSGs out there, but I’m not sure when we will reach v1.0 yet. Hopefully, it’s not too far away.

We have only tested Gridsome with 10k pages so far, which works fine, but I’m not sure if it’s ready for 500k. Our goal is to make it work and support incremental builds to only build what’s necessary on re-builds. But that features isn’t implemented yet…

Sorry for not having any ETAs. We are eager to get things done, but it takes time… 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Images - Gridsome
#Usage via GraphQL. Local image paths from sources can also be compressed. Options like width , height and quality must be set in...
Read more >
Image management via GraphQL by Tamas Piros
In this article, we'll review how to manage images using GraphQL by discussing an application that utilises GraphQL queries and mutations to ...
Read more >
Gridsome Remote GraphQL Source - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
Gridsome Graphql filter variable - vue.js - Stack Overflow
Im trying to query a collection and filter it depends on the $path var but it either returns empty or throwing an error...
Read more >
Blazing-Fast Vue and GraphQL with Gridsome - Reed Barger ...
Concepts Cover: - How to build incredible apps with Vue and GraphQL using ... responsive images with g-image Adding data sources to GraphQL...
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