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.

[gatsby-transformer-json] add graphql-type-json to allow better handling of JSON files

See original GitHub issue

Summary

I’m currently trying to add my package.json file to GraphQL. I already created a plugin which sources single files instead of directories with helpers from gatsby-source-filesystem. But this plugin does not allow me to get all from the key dependencies since GraphQL is explicit. After searching, I found a type plugin for graphql which adds this cap.

https://github.com/taion/graphql-type-json

It would be great if this plugin could be added to gatsby-transformer-json or if we could extend the documentation so that someone can add it by himself.

Here is an Apollo tutorial: https://www.apollographql.com/docs/apollo-server/schema/scalars-enums/#using-a-package

I tried to add it with createResolvers but still get some errors (I know it tells we what exactly is wrong but I don’t know what exactly it means). I’m just starting with GraphQL in deep and don’t really know how to add custom scalars. Would appreciate any help and would create a PR if I get a working version for my portfolio as soon as I get free time for it.

ERROR #11321  PLUGIN

"gatsby-node.js" threw an error while running the createResolvers lifecycle:

Cannot find ObjectTypeComposer with name JSON

Basic example

If the proposal involves a new or changed API, include a basic code example. Omit this section if it’s not applicable.

Motivation

This would enable easier transformation of JSON files and handling like when using require syntax.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
stefanprobstcommented, Feb 3, 2020

@muuvmuuv

  • the content of your package.json file should be available out of the box with:
{
  sitePlugin(name: {eq: "default-site-plugin"}) {
    packageJson {
      dependencies {
        name
        version
      }
    }
  }
}
  • Gatsby (via graphql-compose) already includes a JSON scalar. Did that not work for you?
1reaction
sidharthachatterjeecommented, Feb 12, 2020

Thanks @stefanprobst ❤️

@muuvmuuv Looks like this is resolved for the moment. Closing this issue for now. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

gatsby-transformer-json
gatsby-transformer-json. Parses raw JSON strings into JavaScript objects e.g. from JSON files. Supports arrays of objects and single objects.
Read more >
Reading Data From A JSON File With Gatsby + GraphQL
Goal: Use gatsby-transformer-json to read data from a local JSON file and dynamically generate list items in a React component.
Read more >
Sourcing JSON Data with gatsby-source-filesystem and ...
gatsby-transformer-json : Convert the original JSON format to a JavaScript object. Let's try it out: 1. Add gatsby-source-filesystem and gatsby-transformer- ...
Read more >
Processing large JSON files in Python without running out of ...
Let's see how you can apply this technique to JSON processing. The problem: Python's memory-inefficient JSON loading. For illustrative purposes, ...
Read more >
How to source images and data from JSON files in Gatsby
Turns out there's no way for Gatsby to recognize a path to an image in a JSON file by default. Additionally, I needed...
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